[Solved] Button click with condition not giving expected result

Hi! I’m trying to update a text object with subsequent array children by clicking on a button, but clicking only once updates the text from first to last, rather than one by one.

Here’s a screenshot of how I’m trying to do it:

  1. The TempRes variable starts by default with the same value as Resolution[2].
  2. I set a condition to check if the TempRes holds Resolution[2].
  3. If yes, and a button is clicked, TempRes is updated to Resolution[1].
  4. In the second condition I check the same but updating Resolution[1] to Resolution[0].

Clicking on the button only once, however, updates it from Resolution[2] to Resolution[0]

Any ideas?

It’s creating a chain reaction. All of the events get processed. So, when it’s set to [2] it makes it [1] so the next event is true and it sets it to [0]

It might be easier to use another variable as a counter.

Condition:
Left is clicked

Actions:
Counter - 1
tempRes = resolution[counter]

You could use another function to hide and/or disable the button if it equals 0. You could also change the animation so the user knows it’s disabled. A bit like Windows greys out button. A similar technique I’ll use is to set the objects opacity to like 128 when it’s disabled.

You can do the same thing if you have a right button.

Condition:
Right is clicked

Actions:
Counter + 1
tempRes = resolution[counter]

Note: with a counter variable you could use resolution[counter] instead of using tempRes

NewText = resolution[counter]

1 Like

Thank you!

That’s what I thought was happening, but I still don’t understand why.

The second condition should only be triggered when the button is clicked while TempRes = Resolution[1]. By the time TempRes is updated to Resolution[1] the button is no longer clicked :thinking:

Either way, your solution worked, as usual. I’ll owe you a beer one day :sweat_smile:

I already had the right button ready but still need to make the buttons inactive when they reach the limits of the array, but that should be easy. I haven’t removed the TempRes, because I might still need it, but the point is it works:

1 Like

Variables and other values change instantly but other things like mouse buttons or key presses are the same during the entire frame because they’re updated in between frames.

Each time you use a condition to check something like a key or mouse you’ll get the same result until the next frame.

That is very interesting, and very useful to know. Thanks!

1 Like