How do I…
What is the expected result
there’s a scene variable Turn that i need to toggle between 1 and 2 using a button, and a text box that displays current value of Turn.
What is the actual result
nothing happens.
there’s a scene variable Turn that i need to toggle between 1 and 2 using a button, and a text box that displays current value of Turn.
nothing happens.
What’s happening is that the first variable sets the variable from 1 to 2. However, this meets the second event’s conditions and subsequently subtracts 1 from the variable, setting it back to 1.
To fix this, get rid of the 2 subevents, and add the following action to the “Button_EndTurn” event:
“Change the variable Turn: set to mod(Turn + 1, 2) + 1”
This uses the modulus operator to flip between 1 & 2.
Thank you for replying, but that didn’t work either, counter still stuck at 1. I see what you mean about my original post. shouldn’t this work then? what am I missing? (it also doesn’t)
Nope. It’s creating exactly the same scenario as before. All that’s required is 1 event with 1 condition and 1 action. The only condition you need is:
And the only action will be
“Change the variable Turn: set to mod(Turn + 1, 2) + 1”
There’s no need for anything else.
I tested it and it doesn’t work.
mod(Turn + 1, 2) + 1
(Turn=1)
mod(Turn + 1, 2) + 1
mod(1 + 1, 2) + 1
mod(2, 2) + 1
0+1
1
I had to Google it bc mod() drives me crazy.
This works.
Turn = mod(Turn, 2) +1
Ah, my bad. Thanks for catching it.
i’m almost done with my fisrt game and you guys have no idea how much this helped. you;re the real troopers, thank you so much o7