I have a menu with 2 cards that can have a random upgrade attached. I added a function that randomizes the upgrade that each card has if they have the same upgrade value (so the cards are not equal) and added it in the “_ready()” function, with an “if” statement so that the function is only executed if the cards have the same value.
When the cards are equal, the game somehow freezes, I suspect it has something to do with the “while” loop in the “shuffle_cards()” function is looping infinitely.
Is there any way to stop the infinite looping or convert it into a much safer “for” loop? I appreciate any help.
PD: I am not a native English speaker, I apologize in advance for any misspelt word or weird sentence
Well done on fixing your problem .
You may consider changing the last line to chosen_upgrade = posible_upgrades.front()
as this returns the first element of an array or a null value if it’s empty. Array.front()
In your code, the “1” is an index of an array, which points to the 2nd element of an array (arrays start counting indices from 0). If you ever have less than 2 elements in the array, that line would throw you an out of bounds error. My suggested change keeps it a little safer.