How do I toggle more than two states?

0 favourites
  • 6 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • I'm trying to create a button that will toggle between three states (default=state1, clicked once=state2, clicked twice=state3 and if clicked again, back to state1).

    This is easy if you only have two states, using Else, but I would appreciate a hint about how I can achieve this with more states.

  • Just add an instance variable example "clicked"

    if on touch with button (mouse click) add 1 to "clicked"

    if clicked =o button =default

    if clicked =1 button = state 1

    ......

    .....

    if clicked = or bigger than 4 set clicked to 0

  • Just add an instance variable example "clicked"

    on clicked add 1 to "clicked"

    if clicked =o button =default

    if clicked =1 button = state 1

    ......

    .....

    if clicked = or bigger than 4 set clicked to 0

    Oh, adding to a variable on each click... I was trying with all kinds of combinations using variables, but didn't try to actually add a number each click.

    Thanks, I'll give it a try!

  • Maybe I misunderstood something.

    This is what I tried:

    [attachment=0:30qqi3u2][/attachment:30qqi3u2]

    The default global variable Difficulty="Easy", while the default value for the variable Difficulty on the object DifficultyIcon=1. Frame 0=Easy, Frame 1=Medium, Frame 2=Hard. Howeverm this doesn't seem to be doing anything.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • they should not be nested inside the first condition.

    on mouse clicked add 1 to difficulty

    if difficulty =1 set animation frame to 1 and set system difficulty to medium

    if difficulty =2 set animation frame to 2 and set system difficulty to hard

    if difficulty =0 set animation frame to 3 and set system difficulty to easy

    if difficulty is => 3 set difficulty to 0

  • they should not be nested inside the first condition.

    on mouse clicked add 1 to difficulty

    if difficulty =1 set animation frame to 1 and set system difficulty to medium

    if difficulty =2 set animation frame to 2 and set system difficulty to hard

    if difficulty =0 set animation frame to 3 and set system difficulty to easy

    if difficulty is => 3 set difficulty to 0

    Now I get it. Thanks a lot

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