How do I use Global Variables and Button Objects together

Get help using Construct 2

Post » Fri May 27, 2016 11:10 pm

Hi all,

Here's what I have in my project:

1 Dice Sprite with 6 animation sets - Default, Randomizing and 4 different results. Die has a variable 1-10, representing the 10 sides of the die.
1 Button
1 Global Variable - It has three used values "Waiting", "Rolling" and "Stopped"

Here's what I am trying to do:

1) Sprite is in its "Default" animation state and Global Variable is in its "Waiting" state when the project starts.
2) User clicks on the button and the Dice begins to loop its "Randomizing" animation, and Global Variable is set to "Rolling". 3 seconds go by and the following happens:
--Dice Variable is set to a random value
--Dice Randomizing Animation stops
--Dice animation changes to one that matches up with the dice variable:
----e.g.: If the dice variable is 1, it results in an animation appropriate to that face.

Here's what's actually happening:

1) Sprite is in default state
2) I click the button, the randomizing animation plays because I set the global variable to tell the animation to play "Randomizing" when the global variable is set to "Rolling"
3) 3 seconds go by... and despite me telling the Global Variable to be "Stopped" and there is a condition checking the global variable as "Stopped" and a check for each possible (1-10) result of the Sprite Variable some problems occur: the Global Variable does correctly get set to "Stopped", but the action that rolls a random value for the Sprite's var, (which happens upon pressing the button after the 3 second wait) gets rolled several times before ultimately settling on a value.

What am I doing wrong? I think there's some fundamental lack of knowledge on my part and hope you all can help!

Thanks,
Z
B
9
S
1
Posts: 22
Reputation: 1,069

Post » Sat May 28, 2016 12:32 am

Did you use System-Trigger Once While True in your randomize condition?
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370

Post » Tue May 31, 2016 5:28 am

That did the trick. Figuring out how to use "Trigger Once" was the fundamental knowledge I was lacking. Thank you.

Z
B
9
S
1
Posts: 22
Reputation: 1,069


Return to How do I....?

Who is online

Users browsing this forum: plinkie, rayolf, SashikLV, Yahoo [Bot] and 7 guests