Problem restarting a scene

Hello, I have made a scene with states. The States are just a scene variable. The Initial State = 0, Play State = 1, Dead State = 2, and Pause State = 3. When I preview the game or change from a different scene, the scene starts in my Initial State (0). But for some reason when I restart this scene it starts in the Play State (1). I’ve spent hours trying to figure this out to no avail.

I am using a FSM for this scene. I am also using the [Change the Scene] event to stop the scene and restart it. As always, and ideas or insights would be greatly appreciated. Thanks

Can you share screen shots of the scene’s events, and any external events that are linked to it?





Could it be something to do with my pause state? For some reason if I am in State 2, and I click on the Pause button, it restarts the scene and it’s in the right state of 0.

To answer the question from the first post - when you click the mouse (on a button for some states, but anywhere on the screen by the look of things) as in this condition :

it reloads the scene, which sets state to 0.

However, as soon as the scene has been loaded, and this event kicks in :

and because the mouse button is still down (and not on a pause or sound button), the state changes to 1 straight away


To answer the question from your last post - it’s much the same reason. This condition :

will cause the moon scene to be reloaded when you click on the pause button. And this condition :

will ensure it doesn’t change state to 1, because the cursor is on the pause button.

2 Likes

Thank you for your reply MrMen! I see the problem, I’m just not sure how to fix it at this point. I’ll work the problem for now, but do you have any ideas on how I could rework this?

I got it to work right with a timer! Thank you again for pointing out the problem MrMen. I don’t know what I would do without the support of this forum.

A timer is one way. But what happens if the click/touch lingers, and is longer than the timer?

One more common way is to use a global boolean variable (it persists when changing scenes). You add a condition to the above events that checks the global variable is false. Then add an action that sets the global variable to true.

Remember to also add a new event that sets the global variable to false when LMB is no longer held.