Forum Discussion

GreggLauer-82c2's avatar
GreggLauer-82c2
Community Member
9 months ago

Tracking the order of buttons being pushed

I have 4 buttons that must be clicked in a specific non-linear order to be correct. A message indicating correct or incorrect is displayed. How do I track the order of buttons being clicked using triggers and variables? Thanks!

  • Hi Greg, I'm sure there are a few ways to skin this cat, but one way I can think of is to have four variables, they could be type NUMBER and initialised as 0 (zero). For example:

    step1
    step2
    step3
    step4

    In this example, each button represents a step in making and eating a boiled egg:

    Button 1:  "add oil to the pan"
    Button 2:  "heat the pan"
    Button 3:  "crack egg into pan"
    Button 4:  "cook egg"

    Then, each of those steps, will be assigned a step order. So, if I select "Cook egg", this will assign a value of "4" to the current step, by checking each of the variables step1, step2, step3, step4 by using the following logic:

    On click button "cook egg"

    Set variable step1 = 4 if step1 is equal to 0 (zero)
    Set variable step2 = 4 if step2 is equal to 0 (zero)
    Set variable step3 = 4 if step3 is equal to 0 (zero)
    Set variable step4 = 4 if step4 is equal to 0 (zero)
    Set state "cook egg" disabled

    Each of your buttons would have the same set of triggers, but just updating the number, for example:

    On click button "add oil to the pan"

    Set variable step1 = 1 if step1 is equal to 0 (zero)
    Set variable step2 = 1 if step2 is equal to 0 (zero)
    Set variable step3 = 1 if step3 is equal to 0 (zero)
    Set variable step4 = 1 if step4 is equal to 0 (zero)
    Set state "add oil to pan" disabled

    Ensure that you set the button to disabled when it has been clicked so the user cannot assign the same number to multiple steps

    Then, once the user has selected all of the buttons, in the order they chose, you would just need to check the value of the variables and ensure that step1 is equal to 1 and step2 is equal to 2 etc. This could be done using a Submit button that is enabled once Button 1 to 4 is disabled.

    Cheers,
    Sam

     

  •  

    have four variables, they could be type NUMBER and initialised as 0 (zero). For example:

    step1
    step2
    step3
    step4

    In this example, each button represents a step in making and eating a boiled egg:

    Button 1:  "add oil to the pan"
    Button 2:  "heat the pan"
    Button 3:  "crack egg into pan"
    Button 4:  "cook egg"

    Then, each of those steps, will be assigned a step order. So, if I select "Cook egg", this will assign a value of "4" to the current step, by checking each of the variables step1, step2, step3, step4 by using the following logic:

    On click button "cook egg"

    Set variable step1 = 4 if step1 is equal to 0 (zero)
    Set variable step2 = 4 if step2 is equal to 0 (zero)
    Set variable step3 = 4 if step3 is equal to 0 (zero)
    Set variable step4 = 4 if step4 is equal to 0 (zero)
    Set state "cook egg" disabled

    I’m not right now in a position to test this, but if they all default to 0, then it seems as if clicking “cook egg” will set all of them to 4, because SL will execute all of the “cook egg” triggers when “cook egg” is clicked. Since they are now all “4”, none of the later clicks will change any of them..

    • SamHill's avatar
      SamHill
      Super Hero

      You are right Walt, it would need more logic to determine if any of the variables have yet been set to the current value.

  • Nedim's avatar
    Nedim
    Community Member

    If you want to show immediate feedback after each step/button is clicked, you may get away with creating additional variables. It takes only 8 triggers and some good logic. Check my video. 

  • Nedim's avatar
    Nedim
    Community Member

    It gets more complicated with the Submit button that would appear after all steps/buttons are clicked and disabled. Create a number variable that will track the button clicks. For instance:

    1. Set the state of a button to disabled when the user clicks a button (4 triggers) 
    2. Add value 1 to "clickedSteps" variable when the user clicks a button (4 triggers).
    3. Create another number variable that you can use to validate.

    Example: add value 1 to "correctStep" variable when the user clicks "heat the pan" button (being the first correct step) if "clickedSteps" variable is equal to 1. Then, add value 1 to "correctStep" when the user clicks "add oil to the pan" button (being the second correct step) if "clickedSteps" variable is equal to 2, etc.

    I attached another video showing this option in action.

  • I think this logic would correct the issue.

     

    Set variable step1 = 4
    if step1 is equal to 0 (zero)
    AND step2 is not equal to 4
    AND step3 is not equal to 4
    AND step4 is not equal to 4

    Set variable step2 = 4
    if step2 is equal to 0 (zero)
    AND step1 is not equal to 4
    AND step3 is not equal to 4
    AND step4 is not equal to 4

    Set variable step3 = 4
    if step3 is equal to 0 (zero)
    AND step1 is not equal to 4
    AND step2 is not equal to 4
    AND step4 is not equal to 4

    Set variable step4 = 4
    if step4 is equal to 0 (zero)
    AND step1 is not equal to 4
    AND step2 is not equal to 4
    AND step3 is not equal to 4

  • There are two big problems here.

    The first is addressed by Sam’s posts; not allowing multiple clicks of the same object to mess up the sequence.  The other is to allow the learner to change their mind before submitting. Far too many projects, in both the authoring and testing phases, ignore that important possibility.

    Here's a method I think may be the simplest way to handle both problems.