#Recursion
1 messages · Page 1 of 1 (latest)
I think I found it. You’ll have to check if my theory is right or wrong. Did your error start around the time your BS.times<INSERT_ANIMAL> were all greater than 5?
You mentioned you were playing for about 45 mins or so
if most of your animals were greater than 4 then the elses would always call GenerateN()
@livid hollow
A better way to design your random number generator is to make a list of numbers from 1-9.
To choose a number all you need to do is get access a random index of the list from 0 to list.Count.
Then once that number can no longer be used, you’ll remove it from the list
List<int> nums;
void GenerateNum()
{
if(nums.Count != 0)
N = nums[Random.Range(0, nums.Count)];
}
void RemoveNum(int removeN)
{
// removeN is the number you’ll remove so that it can never be generated again
nums.Remove(removeN);
}
I think not, there were animals that I didn't choose even one time
ah ok, i thought i was into something
no, like 3-4 minutes, and like 25-30 times that the list of upgrades were generated
gotcha
I think I know what you meant, but that wasen't
you got it?
No i understand what you mean
ohh ok
i misinterpreted what you said earlier
this will still help your game regardless
Well, I gotta go, its late in my country and I'm tired of thinking about this problem
alright
I'm still learning c#, and I don't know how to use lists properlly, but I will take your advice
thanks for trying to help man, I appreciate it a lot
in those 3-5 mins did you max out one of your animals to > than 4 at least?
I don't really know, but tomorrow I can see if the problem is that I max out something and it enters a loop. I didn't think of that
if (BS.timesMaxHealth < 5)
{
if (timesChecked == 0)
{
//up
bMaxHealthu.SetActive(true);
}
else if (timesChecked == 1)
{
//center
bMaxHealth.SetActive(true);
}
else if (timesChecked == 2)
{
//down
bMaxHealthd.SetActive(true);
}
}
else
{
GenerateN();
}
The error is from it calling GenerateN() multiple times. Not specifically this one but across your if chain
Yeah i would take a break from this, it’ll help out a bit
so the else state its the one creting the loop?
possibly
the recursion first starts with a method call at line 154. But you can ignore that
all of those lines are lines like: GenerateN(); or CheckN();
yes
the else is somehow triggering, which i’m not sure why
possibly from maxed out animals but i’m not sure
ok, I'll make another method to trigger when you max out something
your right