Skip to main content
nickf2509592
Participant
March 15, 2016
Answered

One button multiple object states

  • March 15, 2016
  • 3 replies
  • 282 views

I'm trying to make an action for a button that will change an objects state the more it is clicked.

I have 3 states - low, med, high

i have 2 buttons - increase and decrease

when increase is clicked

     1 click = low

     2 click = med

     3 click = high

when decrease is clicked

     1 click = minus 1 state

Each advanced action i have made takes me to the last state instead of advancing in order.

    This topic has been closed for replies.
    Correct answer Lilybiri

    As I suspected. All decisions are always executed and due to your sequence

    the last decision will always be done. Reverse the sequence or decrement

    instead of increment.

    3 replies

    nickf2509592
    Participant
    March 15, 2016

    Thanks Rod and Lily.

    The actions i have look like this.  When i click the button this action is assigned to, it skips to the High state.

    Start

         ->If ( clicks == 0)

              clicks = clicks +1

    Low

         -> if ( clicks == 1)

              change state to Low

              clicks = clicks + 1

    Med

         -> if ( clicks == 2)

              change state to Med

              clicks = clicks + 1

    High

         -> if (clicks == 3)

              change state to High

    Lilybiri
    LilybiriCorrect answer
    Legend
    March 15, 2016

    As I suspected. All decisions are always executed and due to your sequence

    the last decision will always be done. Reverse the sequence or decrement

    instead of increment.

    nickf2509592
    Participant
    March 15, 2016

    Thanks Lily, your the best.

    the reverse worked like a charm.

    it now looks like this.

    High

         ->if (clicks == 2)

              change to High

    Med

         ->if (clicks == 1)

              change to Med

              clicks = clicks + 1

    Low

         -> (clicks == 0)

              change to Low

              clicks = clicks +1

    Lilybiri
    Legend
    March 15, 2016

    I suspect the logic in your action is incorrect. Can you post a screenshot of that action using the Preview button in the actions dialog box?

    Sent from my iPad

    RodWard
    Community Expert
    Community Expert
    March 15, 2016

    You haven't indicated how you are achieving the result.

    But I would recommend you have a variable that counts how many times you have clicked the object and then use this in the condition of a Conditional Action with multiple decision blocks.  The first decision block will just increment the variable and then each decision block thereafter will look at the value of the variable and decide whether or not to execute an action to set the state.

    If the variable is initially given a value of 0, then the first time the object is clicked and the Conditional Action is executed, the first decision block increments the value to 1 and the second decision block is set to look for a value of 1 on this variable to execute the change of state to one of the preset states.

    The following two decision blocks will be looking for variable values of 2 and 3 respectively but will not execute their actions on the first click, only for second and third clicks respectively.

    Does this help?

    nickf2509592
    Participant
    March 15, 2016

    Thanks again Rod.

    Your reply did help me a lot.

    Is there a hard copy of your Advanced Actions book?  I only ask because i have CP at work but would need to purchase the book at home.

    Thanks.

    RodWard
    Community Expert
    Community Expert
    March 15, 2016

    Sorry.  It's only available as a downloadable PDF, which you would need to print yourself.