OpusScript Tutorial:

Custom Scoring

How to Keep Score for Games or Custom Activities


Opus automatically tracks a range of scores (values, percentages or correct/incorrect) in internal score variables but these are most easily used for question and answer type interactions. Sometimes you will want to keep score differently - in a game for example.

In this tutorial, we will explore how to set and display a custom score.

Creating a Custom Score Variable

Firstly you'll need somewhere for your score to go. You will need a variable where you can store it and because we want any page in the publication to be able to see the score, it will need to be a Publication variable.

Decide what your variable will be called - for example, userScore and then go to the Variables tab of Publication Properties to create it.

Click the Add button to bring up the dialog to create the variable.

Type the name of your variable in the Name box.

You may prefer to use a consistent convention for creating your variables to help remember what you called something when you come to use it later. Preset Opus variables are always in uppercase so using lower case or title case for yours helps them stand out in the list.

Select the Number option as we will need to add and subtract to this variable so we need it to be a number rather than text.

Set the Initial value to zero unless you want the user to start with a score already.

Triggering the Score

You can use a wide range of activities to record a score in Opus simply by choosing the relevant Trigger. These might include:

But whatever you use to trigger the score, the action will be the same.

Score Action

To increase your score simply use the Add option on the Programming tab.

Click the drop down list to find your scoring variable and then set the value box to the value required.

Displaying the Score

To display your score to the user we simply need to create a text box and put the relevant variable in it.

  1. Click the Text tool on the Tools toolbar and draw a text object on your page.
  2. Click into the text box so the insertion caret appears.
  3. Type "Score: " into the text object.
  4. Next select Insert Variablefrom the Text menu (or the right-click menu if you prefer)
  5. Scroll through the list of the variables to find your UserScore variable.
  6. Click OK and the text object should now include UserScore surrounded by angled brackets to indicate that it is a variable (the content will vary during the progress of the publication). Your text box should now look something like this...
  7. Note If you are publishing to Flash we recommend that you use separate text objects for the "Score: " label and another for the variable alone.

    This enables you to set the Text properties for the variable text to be Dynamic or Device.

    This ensures that Flash will display it as text and not convert it to a vector object which cannot be updated. If you find your score does not change from the original state this may be the problem.

tutorial on keeping score manually in Opus Creator or Opus Pro