#BINARY SEARCH PROBLEMS

1 messages · Page 1 of 1 (latest)

urban cedar
#

oh i have to send a message to create the thread

potent remnant
#

Memory problems?

#

Could you elaborate on that?

urban cedar
#

let me send you the console errors

potent remnant
#

But it was fixed briefly?

urban cedar
#

yeah, by commenting the else statement haha

potent remnant
#

Ah

urban cedar
#

so i figured out the problem was, in fact, the else statement

#

if you need the whole code (for context) lmk :)

potent remnant
#

What does changeTurn do?

#

Also methods should be PascalCase

potent remnant
urban cedar
#

let me update the link to the code then :)

potent remnant
#
IEnumerator IABinary()
    {
        int limSup = allCards.Count - 1;
        int centralCard = ((limSup - limInf) / 2) + limInf;

        if (BinaryAITurn == 0)
        {
            yield return new WaitForSeconds(2);
            TurnCard(allCards[centralCard]);
            limInf = centralCard;
            Debug.Log("middle card is" + limInf);
            myTurn = Turn.playerTurn;
            BinaryAITurn += 1;
            yield break;
        }
        else
        {
            TurnCard(allCards[centralCard]);
            limInf = centralCard;
            Debug.Log("middle card is: " + limInf);
            changeTurn();
        }

        yield break;
    }
#

Just gonna post this bit here since that's the culprit according to you

urban cedar
potent remnant
#

No worries, it just make the code sound funnier so I'm alright with it hehe

#

todas - cartasssss

#

I don't know it's just funny to me heh

#

To be fair if I were to spell out my code in Dutch you'd also have the same spirit heh

urban cedar
#

hahahahahahha

#

yeah hahahahah

potent remnant
#

Maybe you start too many coroutines?

#

I'm not exactly sure when exactly it starts and how often and quick it starts since I can't exactly execute the code

fervent leaf
#

I don t know what a yield is but I have realized that every time you use yield you return a yield wait for 2 seconds but in the else statement you don t

potent remnant
#

Depending on how the coroutine gets called that could be a problem

#

Or how often, rather

urban cedar
#

it’s called just once- on the first time you get this scene

#

so depending on the last scene, the script executes the lineal or binary search

#

(the last scene is a difficulty choosing scene with buttons)

potent remnant
#

If you comment out the execution of changeTurn does it still give the memory errors?

#

Line 103

inland gate
urban cedar
#

let me check

potent remnant
#

That's why I asked kek

urban cedar
#

so

#

how could i fix that?

potent remnant
#

Don't make infinite recursion

inland gate
#

you need to ask yourself why is changeTurn calling IABinary and why is IABinary calling changeTurn

urban cedar
#

okay, thanks everybody, i’ll look into it this afternoon because i have class now, and if i still have problems i’ll message here again, thank you :)