Sorry if the title is indescriptive, I'm just having some trouble defining the issue. I'm trying to make a "Match the Numbers" game, and on the first playthrough, the game works as intended. However, when my notifier gives me the prompt, and I click 'Replay', the 'shuffleNumbers' function doesn't work, and the numbers stay the same. I know it's not something with the function itself because on Screen1.initialize, it shuffles the numbers.
And that's what ABG mentioned. You have to clear the list because now you're just adding to the list, so when you select Replay, your list already has 32 items instead of 16, and the first 16 items are the same as before.
Thank you for the solution! But if I made global shuffleNumbers to an empty list in the function, then how would the numbers in the list get shuffled? Instead, wouldn't it make sense to set global shuffleNumbers to an empty list in the GameOverNotifier code, right before the function? Then, the list will be set empty, THEN set to '1, 1, 2, 2...', then shuffled. Or would that not work?
Clear the list of "shufleNumbers", not "numbers". The numbers for shuffling are taken from the Numbers list.
The first time it works because this list is empty.
I said it should not be in the loop. Now it's in a loop and the numbers are shuffled each time you go through the loop where you set the buttons. You have 19 buttons so the loss is shuffled 19 times.
I picked that spot to clear it because that function has the job of giving you a fresh shuffleNumbers list, and it should shoulder the full responsibility for providing a nice fresh list.
It is one of the principles of coding that each function should hide some details from the rest of the app and shoulder the burden alone, to reduce the complexity of the app.