Hmmm… that’s the first time I’ve used a struct? (I use nullables with ints and bools all the time)… May be a syntax thing… when i get home, I’ll run this through my compiler. I’m sorry this has gotten overcomplicated.
That would be great and no problem If we find a solution for it, it would be great haha!
I think we got sidetracked… The initial problem was that we were dropping two walking sticks… I went back to the original code, created a walking stick and a drop library identical to yours, and after numerous tests, got exactly one walking stick each time…
My Debug was to try and get a read on what was being returned, and that yielded an error, and my fix to that went to more errors, and like the story about Indian Emporer Lahori, we set aside the princess we were building the hall for…
And we’re still stuck with the why… the initial code you posted for the DropConfig may as well have been the code right from the repo. It’s line by line matching.
So with the code editor open, I’ve been working through some Debugs trying to find the issue… I started with a Debug in GetRandomNumberOfDrops()
int GetRandomNumberOfDrops(int level)
{
int min = GetByLevel(minDrops, level);
int max = GetByLevel(maxDrops, level);
int result = Random.Range(min, max);
Debug.Log($"GetRandomNumberOfDrops {level} - {min}->{max}={result}");
return result;
}
I was surprised to discover that my resulting Debug was printed TWICE… Especially since there is only one reference to GetRandomNumberOfDrops, and that’s in GetRandomDrops()
Then I realized that we’re using GetRandomNumberOFDrops in the for loop, which means it’s actually called for every iteration and test… so it’s tested when i=0, then queried again when i++ to make i 1…
So I abstracted that away
int numberOfDrops = GetRandomNumberOfDrops(level);
for (int i = 0; i < numberOfDrops; i++)
{
yield return GetRandomDrop(level, potentialDropInstance);
}
So now I have one debug in GetRandomNumberOfDrops firing, that’s correct… but I’m still no closer to figuring out why you’re getting two items dropped…
Let’s start by getting you back to a running state, by replacing the original script, as posted at the top of the topic.
Once you’ve done that, test, and verify that you’re still getting two drops when there should be one.
Once you’ve done that, I think a closer look is needed, so it’s likely time to zip up the project and upload it to https://gdev.tv/projectupload. Be sure to remove the Library folder to save space. Hopefully, once I have the working project in hand, I can spot the issue quickly, since I can’t reproduce it in the course project.
I am so soory for keeping you busy with my problem for such a long time but something totally weird happend. I replaced the scripts to the original scripts again and tested it, and suddenly it works and its only dropping one walking stick. I tried it for 10 times in a row now and there is no second walking stick in my inventory. I have absolute no idea what happend and why it is working now but maybe it was my very own RPG magic moment. Thank you so much for your effort and time anyway to look into my weird problem!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.