Very Simple guide to using variables

pvalleley3585 Community Member Posts: 17
Hi, I'm quite new to using Lectora online and although I'm doing ok I cannot understand variables.  I've looked at a number of examples online but am still struggling to create even a simple one. ☹️

Are there any really (really) simple step by step guides to say, stop a user using the next button unless they have clicked on three different images (in any order).  I have looked at several of these but usually there are more options than my brain can cope with!  Can anyone help get me started?



  • smiller7502
    smiller7502 Community Member Posts: 181
    Pip, see if this gets you started:

    Create Your Variables
    1. On the Tools tab, click Variables.
    2. Click Add.
    3. In the Variable Name box, type a name for your variable. The name can be any combination of letters and numbers, plus _. For this example, create a variable called Button1Clicked.
    4. In the Initial Value box, type False.
    5. Check the box labeled Retain variable value between sessions.
    6. Click OK.
    7. Repeat steps 2-6 to add variables called Button2Clicked and Button3Clicked.
    8. Click Close.
    Assign Actions to Your Buttons
    1. Click the action for your first button. (If it doesn't have an action yet, add one.)
    2. Click the Action tab.
    3. Be sure the Trigger is set to Mouse Click.
    4. Click No Action (or whatever action is already assigned in the Action and Target group) and then click Modify Variable from the menu that appears. You'll see three text boxes appear next to what is now a Modify Variable button on the ribbon.
    5. In the Target box, click Button1Clicked.
    6. Be sure the Type box says Set Equal To.
    7. In the Value box, type True.
    8. Repeat steps 1-7 for your second and third buttons.
    Controlling the Next Button

    There are a couple of choices here. You can set the Next button to initially hidden and then show it, or you can disable it and then enable it. For this example, I'll assume you've set it to initially hidden.
    1. Click your first button again.
    2. Add a second action to it.
    3. Be sure the Trigger is set to Mouse Click.
    4. Click No Action and then click Show. You'll see one box appear beside the Show button.
    5. In that Target box, click your Next button.
    6. Click Always. You will see a pop-up screen called Set Action Conditions. There are three columns in this box, labeled Variable, Relationship and Value.
    7. On the first row, in the Variable column, pick Button1Clicked.
    8. On the first row, in the Relationship column, pick Equal To.
    9. On the first row, in the Value column, type True.
    10. Repeat steps 7-9 on the second row for the Button2Clicked variable.
    11. Repeat steps 7-9 on the third row for the Button3Clicked variable.
    12. Be sure the box above the Variable column says All conditions must be true.
    13. Click OK.
    14. Copy this new action to your second and third buttons.
    You're done! Each time a learner clicks one of your buttons, the variable for that button will be set to True, and if all three variables are set to True then the Next button will appear.

    Hope that helps!

  • klaatu
    klaatu Community Member Posts: 988
    In this example the participant must click each button once before the next button is enabled allowing passage to the following page.

    In order to do this we need to have a way of monitoring if a button gets checked. I set up a separate variable for each button, naming them btn1, btn2 and btn3. Because we only need to watch for two states, clicked or unclicked, I decided to use Boolean values true/false. I made the initial value of each of the btn variables false to denote that they have not been clicked.

    Next we have to modify the variable when the button is clicked. This is done by adding an on click action - modify variable - set btn1 to true. Do this for each button making sure you modify the correct variable for each button (ie: button2's variable is btn2, etc.)

    Finally, we need to check to see if each btn is true, meaning they were all clicked. This is done by adding another on click action to each button (3rd action). This action says to enable the NEXT button ONLY IF btn1 = true AND btn2 = true AND btn3=true.
    So, if you examine the actions for "Button" you'll see:

    OnMClkShow - Shows the initially hidden text box witht the 1 in it.
    OnMClkModVar - sets btn1 to "true" (no quotes).
    OnMClkSetState - Checks all three variables, one at a time, to see if they are all "true". If they are then the NEXT button becomes enabled.
  • pvalleley3585
    pvalleley3585 Community Member Posts: 17
    Hi Stan

    You're a genius, I have finally managed to do this :)

    Slight hiccup because I didn't copy the Action Conditions to the other buttons but once corrected it worked.  Thank you so much for this.

    Kind regards



  • jasonadal
    jasonadal Community Member Posts: 441 ♪ Opening Act ♪
    I'll add another piece that may be helpful as well (if this is redundant, I apologize, as I didn't have a chance to look at Darren's sample).

    With the setup that you're using, if the learner revists the page, they may have to click the buttons again in order to get the next button to appear depending on how you configured the page to hide the next button. I've used a similar approach to control the next button, text on a page or even which image appears based on variables.

    For the next button, what I have typically done is add this action at the top of the page:

    OnShow: Show Next IF variable1 = true, variable2 = true, etc.
    Else: Hide next.

    This will determine whether to show or hide the next button when the page loads. I use this method rather than the visited state of the page, as it seems to be less quirky.
  • knunez-5445
    knunez-5445 Community Member Posts: 3

    I have followed all the directions here and my "Forward button" doesn't appear.  I have the three actions under the buttons, The initial purpose of the button, the Modify Variable, and the Show Forward Button actions. I double checked all targets and conditions are the same.

    In the variables manager, I made sure that all initial variables were False and we are retaining value.

    I also have the show action (the one that is supposed to show the Forward button only after the three buttons are clicked) under all three buttons.

    The forward button is set to initially hidden, but when I click on the three buttons, it won't appear.

    Any ideas where I could have gone wrong?

    I have also tried the action on the button itself as suggested by Jason.  I feel like I may be missing something... Any info is appreciated!





  • mnotermans5114
    mnotermans5114 Community Member Posts: 916 ☆ Roadie ☆
    When things get tough with variables... i make some extra actions and a textfield that will show the value of a specific variable onscreen. That way its 100% easier to test and debug your project and mostly easy to find where something goes wrong...
  • carlfink
    carlfink Community Member Posts: 1,102 ✭ Legend ✭
    In addition to what Math says, you could turn on debugging, which lets you see the values of all variables while running the course.


    Publish >> HTML >> Publish >> Debug >> Debug Published Content


    By using the HTML option, you can then Preview the course locally, and see the debug window.