How do I have button click update global variable only once per click?

0 favourites
  • 5 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I have something like a binary tree/choose your own adventure mechanic. I present multiple questions and the user can go right or left at each question. I keep track of this with a global variable called questionNumber. When the user clicks buttonRight, I would like for the global variable to be updated only once. However, with my current set up, the global variable is going from 0 to 2 to 6 to 15 from just one click.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could get rid of the trigger once they're not needed and replace them with Else except for the first condition, it would work.

  • The events inside the triggered event are still working top to bottom. So if your variable is 0, in that tick it is set to 2, then also within that tick the next condition is true, so the variable is set to 4 and so on.

    Add "wait 0" before the actions in each sub event so that the condition check happens once in the first tick, and then the variable is not updated until the following tick.

    And yes, you don't need the trigger once conditions.

  • The "wait 0" did work. Also, right after I posted I tried reversing the order and that worked as well. Thank you!!

  • Yep, reversing the order also works if you have consistently increasing/decreasing values. A neater way when you have a lot of values that correlate to other values is to use an array.

    Have a look at this example: 1drv.ms/u/s!AkmrWgxeuxlKhJt7zAIIWrjosCGmpg

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)