How do I use Global Variables and Button Objects together

  • 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

  • Did you use System-Trigger Once While True in your randomize condition?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That did the trick. Figuring out how to use "Trigger Once" was the fundamental knowledge I was lacking. Thank you.

    Z

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