#Recursion

1 messages · Page 1 of 1 (latest)

potent moon
#

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);
}
livid hollow
potent moon
#

ah ok, i thought i was into something

livid hollow
potent moon
#

gotcha

livid hollow
livid hollow
potent moon
#

No i understand what you mean

livid hollow
#

ohh ok

potent moon
#

i misinterpreted what you said earlier

potent moon
livid hollow
#

Well, I gotta go, its late in my country and I'm tired of thinking about this problem

potent moon
#

alright

livid hollow
#

thanks for trying to help man, I appreciate it a lot

potent moon
livid hollow
#

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

potent moon
#
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

livid hollow
#

so the else state its the one creting the loop?

potent moon
#

possibly

#

the recursion first starts with a method call at line 154. But you can ignore that

livid hollow
potent moon
#

yes

#

the else is somehow triggering, which i’m not sure why

#

possibly from maxed out animals but i’m not sure

livid hollow
#

ok, I'll make another method to trigger when you max out something

potent moon
#

definitely take a break first though. A fresh mind helps a lot

#

good luck tmrw

livid hollow
#

have a great day

#

youre awesome dude

livid hollow
#

Hello!

#

I fixed it!

#

It was that, when a lot of upgrades were maxed out, it started lagging till the point it didn't generate more

#

I changed the max out sistem and now it works!

#

Thank you so much, without you I couldn't do it