Prevent code from executing till alert is confirmed

Hi,

I am trying to put in a game where the user can play with the computer similar to snake and ladders. When the user hits a danger block, an alert is shown that the user has to spawn again and used the “wasconfirmed” to confirm if the button is pressed. The code automatically plays for the computer.

The issue I am facing is when the alert is shown, before the confirmation button is pressed, the computer starts playing (ie remaining code is getting executed when the alert screen is shown). Is there a way to prevent it?

Code snippet is shown. So if the player is poisoned, the alert will show. But before confirmation the next set of code is being run.
Capture

We can’t tell what the problem is just from that small amount of code. But I can suggest something: when the alert is shown and the confirm button is clicked, change the value of a variable to indicate that the player’s turn is over. Then, in your code that starts the computer’s turn, check to see if that variable has been changed.

3 Likes