#BINARY SEARCH PROBLEMS
1 messages · Page 1 of 1 (latest)
But it was fixed briefly?
yeah, by commenting the else statement haha
Ah
so i figured out the problem was, in fact, the else statement
if you need the whole code (for context) lmk :)
Yes please
let me update the link to the code then :)
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
https://hatebin.com/rcduvanuqq (there are some spanish comments which are just false code to guide myself through all this haha)
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
no te procupes
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
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
Depending on how the coroutine gets called that could be a problem
Or how often, rather
hence this
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)
If you comment out the execution of changeTurn does it still give the memory errors?
Line 103
IABinary calls TurnCard which calls changeTurn which can start IABinary again
let me check
ohhhhhh
So it is the coroutine calling too many times
That's why I asked kek
Don't make infinite recursion
you need to ask yourself why is changeTurn calling IABinary and why is IABinary calling changeTurn
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 :)