Why doesnt this logic work?

I have been looking at basic quiz logic and how I would implement it like I have in other ways, but for some reason I can’t seem to see the logic only works with 2 questions any more and I skips to the final question. I have tested it using the basic navigation logic as shown in the screenshot .

Essentially with a button and a text object and a page number variable my logic is:

Set page number variable to 1

if click button set page number variable to 2

If page number variable is 2 then change text to page 2

if page number variable is 2, and button clicked set page number variable to 3

if page number variable is 3 change text to Page 3

any ideas on why this skips to the final number rather than the next number?

Because the second/selected event is also true if the variable is 2.


Every frame the computer reads your whole code, from top to bottom.
“left button is released” is true for the whole frame, so each condition of your frame become true in a row, and your variable pagenumber become 2 and then directly 3.

Another remark:
such a system could work, but is really heavy, I mean each time you want to add a page, you’ll need to add event for this specific page.

Here is an easy way to do things (with only a few events for all pages):

if left button released, and cursor on the button :

  • → variable pagenumber add 1
  • → change text of “ChangeText” object, set to VariableString(text[VariableString(pagenumber)])

in you game datas you would have at the beginning of the scene, all texts stored as text.1=… , text.2=…, etc.

For more information about this, see the wiki page about variable, and especially how to dynamically use variable children.

1 Like

Thanks for this info- I am pretty new to Gdevelop so have just been trying a few different ways to replicate things I have done in other code in the past. What you are saying makes perfect sense - in my head I felt like it was all being executed but whatever conditional I added in this flow caused the same result!! Makes sense that it is the left button release, although I assumed the added conditionals would create a unique requirement for each conditional so need to get my head round that a bit!

Maybe some of this can be helpful: [Example] Simple math test (randomized, with multiple answers)