Conditional behavior to occur based on the score (Advanced Version)

MINI LESSONS ›› Quiz Related Topics ››

MINI LESSON

CONDITIONAL SCORE LOGIC (Advanced Version)

The Score button in ToolBook will provide you with the ability to show the user their current score. For many of you this will be enough to meet your needs. Others will want to go a step further and perform different actions depending on the achieved score.


To do this you will need to use the Actions Editor within ToolBook Instructor to analyze the score, and then set up some conditional behavior to occur based on that score. You will need to be familiar with the Actions Editor in order to implement this type of solution.


There are two versions of this Mini Lesson

  1. Basic Version
    The Basic Version is easier to implement but not as flexible. To view the Basic Version, click here.
  2. Advanced Version
    You are viewing the Advanced Version now. The Advanced Version is more complex to implement but provides you with more flexibility, such as being able to use the Percentage achieved by the user, within your branching logic calculations.


OVERVIEW

In this demonstration the behavior will be as follows:



STEP 1 - ADDING A SCORE FIELD

On your summary page, add a Score field. You will find one of these in the Scoring and Tracking category of the catalog.


STEP 2 - CREATING THE PASS/FAIL TEXT FIELDS

In order to tell the use they have passed or failed, two fields will be used. Informally I'll refer to these as the Pass Text Field and Fail Text Field .


You'll need to add two text fields to your summary page for this purpose.


  1. Name one of the fields: Pass
  2. Name the other one: Fail
  3. Put appropriate text in each field to tell the user they passed or failed


Finally the Summary Page needs to be configured so that whenever it is Reset, the Pass and Fail text fields will be hidden (Note that a page is reset automatically immediately before it is exported to DHTML format - as well as when you do a Save of your book and choose to do a Reset type Save).


  1. Open the Actions Editor for the Summary page
     
  2. This will default to showing you the On load page... event
     
  3. Click on On load page and choose On Reset from the options displayed
     
  4. Add two Set Property actions
     
  5. Configure them as shown below

     
  6. Close the Actions Editor, allowing it to save the changes


STEP 3 - ADDING THE ACTION TIMER

In ToolBook there is no built-in command in the Actions Editor to calculate the score and have that score be available to you as a percentage. Instead ToolBook only makes the score available to you as the number of points achieved.


However, in our example we need to be able to judge the user based on Percentage. In order to do that, we have to devise a workaround, and that is as follows:


  1. Let ToolBook show the score to the user in this format:  Score: 85%
  2. Using Actions Editor logic, read the displayed value out of the Score Field
  3. Using the Actions Editor, toss away the percent symbol
  4. Using the Actions Editor, toss away the "Score: " portion
  5. This leaves just the raw number (as a percentage value) which we can use to determine if they passed or failed.


This workaround suffers from an interesting problem. When you ask ToolBook to Score your quiz, ToolBook will display that score within the Score field once it is finished calculating it. This calculation process is extremely fast in a Native ToolBook application, however in DHTML format, this can take several seconds to execute within a browser. This means we need to be careful to not try to read the Score value, out of the Score field, until after ToolBook has actually put the score in there.


The solution is to use an Action Timer to periodically check the field to see if it is still empty. When it is no longer empty, the score must now be there, and we can proceed with analyzing the score.


The Actions Editor logic to score the book, as well as the conditional logic will both be placed in the Action Timer.


  1. Add an Action Timer onto your page from the Action Objects category of the Catalog (this object is only visible in your book at Author level).
     
  2. In the Properties for Action Timer dialog, on the General tab choose Countdown for the Type of Timer and ensure that Auto start and Fire events are selected.

     
  3. On the Time Markers tab, Periodic should already be chosen and you should set its value to 500 ms.

     
  4. Click OK to close the Properties for Action Timer dialog.


By configuring the Action Timer in the manner described above an On media timing event will be triggered every 500ms. Step 5 will take care of handling this event.


STEP 4 - ADDING THE SCORE LOGIC TO THE ACTION TIMER

In order to get ToolBook to display the score in the Score field, it is necessary to tell ToolBook to Score the quiz. Although there is a Score This Quiz button in the Scoring and Tracking category of the catalog, this demonstration will not be using that button. Instead the Score action within the Actions Editor will be used.


The goal is to have the score shown to the user as soon as they enter the Summary page. As such we need to add logic to the On Load Page event for the Action Timer.


  1. Open the Actions Editor for the Action Timer you previously added to the Summary page.
     
  2. By default the On Media Complete event will be showing.
     
  3. You will need to click on the term On Media Complete and choose On Load Page from the choices shown to you.
     
  4. From the Scoring and Tracking category on the side panel in the Actions Editor add a Score Pages action.
     
  5. To adjust the properties of your Score Pages action, double-click the lightening bolt at the front of that newly added line within the Actions Editor window.
     
  6. The Properties for Score Pages Action dialog will open.
     
  7. On the General tab ensure that you configure this to score All pages in the book.

     
  8. On the Options tab, ensure that the Show Question Score checkbox is checked, and that the Percent of Maximum Score is chosen. This will cause the score to be shown in this format: Score: 78%

     
  9. Click OK to close the Properties dialog and your Actions Editor window should show the following.

     
  10. Close the Actions Editor allowing it to save the changes.


STEP 5 - ADDING THE CONDITIONAL BRANCHING LOGIC

The conditional logic will also be added to the Actions Editor for the Action Timer. The logic will be under the On media timing event.


  1. Open the Actions Editor for the Action Timer.
     
  2. Choose the On media timing event...
     
  3. This time before we begin adding code, we need to create a variable to store the score.
  1. Use the Actions Editor to build the following logic:


Every time the On media timing event is triggered (every 500ms) ToolBook will check to see if the Score field is populated with the score, and if it is then it will show the correct Pass or Fail text field.

 

The only line in this code which will likely look confusing is the one which says:

 

  set myScore to characters 8 to (charcount(text of field "Score") - 1) of text of field "Score"

 

Although it is not necessary for you to understand how it works since it works without any modifications needed, if you are curious, here is what it is doing:

 

The Score field will be holding a value such as: Score: 78%

 

Although this looks great for display purposes it does us little good when what we need is just the number...the 78.In order to extract out just the number and leave the rest behind we need to extract characters (8) through (one less than the number of characters in the string). This tosses out the % and also the "Score: ", leaving just the raw number which we can use for computational purposes.
 

  1. Once the raw score value is stored in the variable, you can use various IF statements to perform different actions based on the score.
     
  2. Close the Actions Editor allowing it to save the changes.



Created with the Personal Edition of HelpNDoc: Full-featured EBook editor