Tuesday, March 30, 2010

Unlocking the Power of Lectora Variables, Part 1

By Jay Lambert

As we network with newer Lectora developers, we are often asked to clarify the use of variables in the tool. As a reminder, variables within Lectora hold key pieces of information that you can later refer to and act upon.

My next few posts will attempt to provide a primer on using Lectora variables to accomplish a few basic tasks. Once you begin using them, all sorts of possible uses will emerge.

Note that the actions I’ll mention are included as part of the normal Action dialog box drop-down list.


And once you add a new custom variable to a course, it also becomes available for you to select in an Action dialog box drop-down list.

So once you get the hang of it, you are really just selecting things rather than having to structure the code yourself (like you would in JavaScript). Once your initial variable and actions are set up, this saves you a lot of time.

For our first example, let’s manipulate a variable to enable navigation within a course. In another post, we will look at testing against an answered question and then later at using a learner’s name within text in a course.

Navigation example

Suppose that you have three photos on a page and you want the learner to click on each to reveal some hidden text. The text is important so you don’t want the learner to be able to leave the page without clicking each of the three photos. You can create a variable to help with this.

1. In this scenario, first disinherit the next button from the page. Add a copy of the same Next button back to the page and make the On Click setting of that button (on the On Click tab) ‘None’ (meaning it won’t advance until you add another action to it).


2. Next, add an action to each of the three photos. The action would be On Click, Modify variable _gonext (or whatever you want to name it, but I recommend using the underscore at the beginning of the name because it will make it list at the top of the variables list so you can easily find it).

3. Then select ‘Add to variable.’ For one of the photos, enter the letter a (‘a’), for the second b, and for the third c. Some developers will simply add the number ‘1’ to the variable each time a photo is clicked, resulting in the value equaling ‘3’ once all three photos have been clicked. That will work too; however, Lectora won’t know if the learner simply clicked the same photo three times in a row, resulting in the variable = 3, rather than knowing that the three separate photos were clicked. Using letters gives you a lot more control.

(Note that I also recommend manipulating a single variable as much as possible rather than creating a unique variable for each photo; the fewer variables you have to track and test against later, the simpler your coding becomes.)

For example, the action on the second photo would look like this.


So now, once the learner clicks all three photos, the _gonext variable will equal some combination of “abc” depending upon which order the photos were clicked (if they clicked them in opposite order, the variable will equal “cba”).

4. At this point, add an action to the Next button (that you just added to the page) that instructs On Click, Go to Next Page.


5. And here is where the variable comes in. Go to the conditions tab of the action and add three conditions:
  • If _gonext Contains a
  • If _gonext Contains b
  • If _gonext Contains c

It’s important that you use three separate conditions because you don’t know in which order “abc” will appear. By setting your conditions this way, it doesn’t matter which photo the learner clicks first and you won't have to test against all the possible options. It only matters that they do indeed click each photo.

It’s also important that you select‘All of the Following.’ This instructs Lectora to only perform the action if all of the criteria is met. The default setting is ‘Any of the Following’ which means that your learner could advance after clicking only one of the photos.



Now that you’ve done all this, the Next button won’t work unless the learner clicks all three photos and at least sees whatever you intended.

6. As a best practice, you might also have a hidden text box on the page that says “You must click each photo before continuing.” or something similar. This way the learner will know why they can’t advance to the next page if they click the Next button before completing the criteria you established.


If you want to add this functionality, go to the Else tab of the Action you just created on the Next button and instruct it to show this text box.


Now the text box will show if the learner clicked the Next button but all three photos had not been clicked (in other words, the condition we just set failed).

Hopefully this post is helpful to those of you exploring Lectora variables for the first time. I’ll provide another example in my next post.

And, as always, if you have any questions, please let me know.

10 comments:

  1. Thanks for the tips. Good stuff. I've never used variables before but want to try experimenting.

    ReplyDelete
  2. Thank you!!! You really helped me understand more about variables. I am just learning this part of Lectora.

    ReplyDelete
  3. Replies
    1. Can a variable contain multiple values? It seems one value would replace the previous unless separate variables were created. I'm new; can you tell?

      Delete
    2. Loni, yes, one variable can contain multiple values that you can search on as long as they are simple, such as a single letter.

      When you modify the variable using a Lectora action, change the default setting of 'set variable' to 'add to variable.'

      Each time you want to add to it, add a character such as a, b, c, etc.

      Then to act based on what the variable contains, you would add a condition to that Lectora action that if xyz variable contains 'a' and contains 'b' (and so forth), then do this new action.

      If you want all of the variable's values to be considered for the condition, then make sure you indicate that on the condition dialog box; the Lectora default will be if any of the values exist, not all.

      Also, enter each value you want tested against as its own line in the condition dialog. 'a' and 'b' and 'c' is very different from 'abc' because by listing them separately, they can be in any order within the variable and still be recognized.

      Hope this helps! Feel free to post any follow-up questions.

      Delete
  4. Hi - Thanks for the very useful article. I was wondering if you know what the value for an test score variable is when all the questions have been answered correctly - is it 100 (as in 100%), or is it the number of total questions (as in, 3 out of 3 right)? Thanks again!

    ReplyDelete
  5. Hi, the test score variable should contain the correct percentage (as in 100%). Lectora will compare this score to the minimum passing score you set in the Test properties' Results tab to determine if the test was passed or not.

    But, to be safe, you can always test this out (or any other variable you are not sure about). On the page after your test has been submitted, add a new text box with the word "score" in it; then add an action to the page that On Show of page, Change contents of this text box to the test score variable. Then publish your course and take the test. When you reach the page after the test, the contents of the test variable will display on the page. Then you will know for sure exactly what is there.

    Once you are done testing, remember to delete this action before you publish again; otherwise it will still be in the course when you launch it for the learners.

    Let me know if you have more questions about this.

    ReplyDelete
  6. Hi Jay,

    Is there a way to display the value of the variable?

    Let's say I wanted the learner to make their way through a maze and I was using a variable to keep track of every turn they made. Basically I was adding to the variable at each screen in a branching scenario. At then end I want the screen to say, "It took you ___ tries to get through maze. The fastest path is 10. Try again?" How would I display the value of the variable?

    ReplyDelete
  7. Yes, you can do that.

    On the last screen, add a text box and name it something relevant such as 'Number Tries.'

    Then add an action to that last page that states:
    On Show (of page), Change Contents, and select the text box you created as the target. Then, for the content, enter the variable you are using to track the attempt.

    Now when the page displays, it will populate the text box with the number contained in the variable.

    You will need to adjust the text box's location on the page so that it matches up well with the sentence around it. To do this, I will usually use a series of text boxes and then lock the size/location of each so they don't move when published.

    Hope this helps.

    ReplyDelete
  8. I have created a test with 3 sections. Each section has questions with multiple choice responses. The sections are branching scenarios, so I assigned each selection in the question with a different value to each section's variable. For examples, Q1 has three choices: best, okay, and bad: best = 5 points, okay = 2, and bad = 0.

    This is all functioning very well. However, now I want to add the three section's points together as the final "grade" when the user completes the three sections. I figured the additions of points (and assigning question values to 0 in order to differentiate between the points) would render the entire test unreliable, which is the case.

    Basically, I want it to rate the user like in those magazine quizzes like 90-100% you are great; 70-90% you can use improvement but you've passed the assessment; and below 70% go back and redo the course. There has to be a very simple solution - I am thinking somehow adding the three section variables together. How would I do this? Or any better ideas?

    Thanks!

    ReplyDelete

Thank you for your comments.