How do I use a global variable to stop scenes from skipping?

Hi helpful people,

I’m new to GDevelop. I’m creating a quiz game where each question has its own scene (Q1 scene > Q1 feedback scene > Q2 scene > Q2 feedback scene etc…). When the player selects an answer option, I want them to move onto the next scene.

Current problem: when I select an answer option, it skips multiple scenes, taking me straight to the end scene. Oddly, it doesn’t always do this and it can also vary with the number of scenes it skips - sometimes it skips just one or two scenes, but often it skips to the end scene.

I’ve found threads with the same problem. The solution proposed there is to create a global variable that’s set to 1 when the key is pressed, then changes to 0 when the key is released. Then it’s advised to set a condition where the scene changes only when the global variable is 0.

I’ve tried the above solution, but can’t get it to work so must be doing something wrong. I’ve tried various things, but to no avail. In my game, I want it to be a mouse click on an answer option that changes the scene, rather than a key press. I’ve created a global boolean variable called ‘ChangeScene’ that sets to false at the beginning of the scene. Then, when the player releases the mouse click on an answer option, I’ve set the ChangeScene variable to change to true. Then I’ve added a condition to change the scene when ChangeScene is true. This doesn’t work - it doesn’t change the scene at all.

Here’s a screenshot of the events. I have no idea what I’m doing wrong, so any help would be very very much appreciated. Many thanks in advance!

Hey, I’m just a new as you are here, but I would like to take a crack at this problem.

So in my games I don’t change scenes very often at the moment. I literally have a project Scene that shows all the things I am working on and then you click on which project you want to test out and it sends you to that scene or few scenes depending on the project.

However, I think there are a lot of ways you can go about this depending on what you would like to do.

It almost sounds like your issues at the beginning of the post could be solved by adding the trigger once event if you can get back to that original set up.

Though for me, I am struggling to figure out why it would launch you to the end of the quiz. Normally for me, my scene buttons only send someone to one specific scene. Though, for your issues that will require a lot of work that I am certain isn’t needed if we go about it properly.

I do get a little confused when trying to follow your logic, but I do like the idea with the boolean variable. Only that gives you just true or false. If you utilized an array and utilized a little bit of math you can make your answers add or take away the total and the total you are left with dictates which scene you go to. (Just in case they are actually allowed to take different paths to the final.)

I am not an expert, but I am more than willing to test out the game if you have a link you want to share. I will have some free time today and I think GDevelop has a discord, I will see if I can put myself on that as well just in case you’re like me when it comes to working on problems and like quicker feedback.

Thanks for your reply and ideas!

I tried adding trigger once (and in various places for good measure), but that didn’t make a difference either. Apparently, the reason why it skips scenes is that the scene change happens in a single frame, but it’s not possible to press a key/click within a single frame (we couldn’t press/click fast enough), so I think it keeps changing scene until the key is released. So the purpose of the boolean variable is to make sure that it registers the key as released before it changes the scene.

It seems like a few people have solved the problem using a global variable in this way, I just can’t seem to crack it myself, so wondered if anybody knows how I’m misapplying it.

Thanks again :slight_smile:

Why do you have a boolean define if the scene changes? If you just made the mouse button release that should work. In gdevelop. Any mouse/keyboard key pressed counts for an entire frame. But I think I know the issue. When you have the boolean on. It’s constantly on going through the scenes. That’s why you make a mouse button release do it instead. The actions: cursor is on “object” then mouse button released “any” and that should work

Not a problem, also I want to elaborate on what GamesByMe said. So the way I understand it is yes however long you have the key pressed is how many times it will trigger when you don’t have the trigger one while conditions are true on there. So say your game runs at 30 frames per second and you hit the button for one press, it will launch you forward for however many frames passed during that time.

So button release should solve that.

I think the global variable isn’t a bad idea, but it does seem to be a little much for what you need.

If the boolean isn’t set to false before a scene doesn’t end. It will do that on repeat. “At the beginning of the scene” is a slower condition than most. So the scene ends before that can trigger it seems. EDIT: Yes you can most likely get the Boolean to work just make an action on the scene changing event before it changes the scene. Like set boolean to false “wait 0.01s” then change the scene. And that’s another possibility less complicated

Thanks both. That’s what I originally thought, but it doesn’t work either. This is what I had before and I had the same problem of getting stuck on the scene – when the events look like this, I just get stuck on the scene.

Weird. Try doing what I last said tho EDIT also if you didn’t know, all events reset whenever a new scene starts

Some times it can help to have a little bit of debug via the console to see exactly what is not getting triggered. Remaking your example (roughly) you can see that the mouse released is not getting trigged.


image

Logic in Gdevelop is read/executed from top to bottom, so you’re essentially asking the engine to check if the mouse is pressed down whilst also released, so the moment you release the mouse the previous check is invalid leading to the released section not getting executed.

I would suggest just check if the mouse was released AND on the object. Changing it to something like the below ill get the expected results.


image

2 Likes

Thank you for looking into this and such a thorough response - that’s really helpful and also has taught me how to use debugging much more effectively, so thank you! Also makes a lot of sense. I’ll try your solution and see if that works.

I’m not even sure if I’ve correctly diagnosed the problem as to why it’s skipping scenes, as the behaviour is inconsistent - sometimes it skips scenes and other times not, and it also varies with the number of scenes it skips. So I’ll play around to see if I can figure out patterns in behaviour that might be more diagnostic of the problem.

Thanks again!

1 Like

Just to update - @Eiklahc trying your solution of switching round the conditions to have the mouse release and then the cursor/touch on the correct box seems to have solved the problem. No need for a boolean variable to change the scene - it seems to work fine with the standard change scene event when the conditions are ordered in this way. Thanks again - life saver :slight_smile:

2 Likes