Everyday Features:

Variables

using content which changes

Timelines in Multimedia Authoring montage

Variables are a fundamental component of programming languages but as implemented in Opus they need no programming skills to use. They can be simply thought of as pigeonholes where you can store information which changes while the publication is running but which you want to use at some point. This might be a user’s name, a record of progress, an order or a score. The name of the variable is a label you can use to get at the information it contains.

You can set the content of a variable when you create it or it can be changed as the publication is used, either by user actions such as typing information into a text input box or by programmed actions by using the Set Variable action.

You can set up actions that will change the information in a variable and then set other actions to only proceed if the information in a variable matches a condition you set. Some variables can be set to be “persistent” that is other pages can use them, whilst others can be restricted to specific pages which means if you try to use them elsewhere in the publication they will not be visible.

Adding Text

The Set Variable action allows you to set the information in a variable and the If...then action lets you make an action dependent on what is in a variable. Both of these items are available on the Programming actions tab.

Creating a Variable

Opus includes some built-in variables to store scores for the internal scoring facility and to provide access to the system time and date, but you will also want to create your own for other purposes. This can be done at almost any point where you use a variable by clicking the New… or Create New Variable button, most commonly when you use the Set Variable action to make the variable available to the program. Alternatively you can also set up all the variables you think you will need via the Variables tab on the Properties for a page that also lists all the custom variables available on that page. Click the Add button to create new variables. This will call up a simple New Variable dialog and you simply type the name of the new variable in the edit box provided. Note that you cannot include spaces in the variable name and we recommend you use capital letters throughout so that variables are easy to spot in text. You do not need to put the angled brackets, < >, round the name. These only need to be used when typing the variable name into script or edit boxes.

Types of Variables

Using Variables

You can use variables simply to display information, such as a username, a score, or the current date on a page. Alternatively you can use the variable in a programmed action to change the subsequent activity of the publication by comparing the content of the variable with other values to decide how to proceed. This is called conditional branching.

Variables are also used within programming actions to provide counters for loops or to temporarily hold information while it is manipulated by maths or other functions.

Conditional Branching

Many programs use conditional branching to decide between one or more course of actions depending on what has gone before. For example you may want to check if a score is over 80% in order to decide whether the user has passed a test or not.

Maths Functions

Opus provides a wide range of Maths fucntions which allow you to perform addition, subtraction and multiplication of numbers.

Displaying Variables

Text objects can be used to display variables such as usernames or scores.

Simply create a text box or click anywhere in an existing one and then select Insert Variable from the Text menu and select the variable you want to use. In the editor the variable name will be displayed, surrounded by angled brackets, but when the program runs the text will display the content put into that variable (if there is any).

Note: For HTML5 and Flash output the Text object must be set to dynamic to allow the variable to be updated when the publication is run. This is usually done automatically by Opus but if you have problems displaying a variable in HTML5 then check this first.

Variables on Buttons

You can display variables on buttons in exactly the same way. Select the caption of the button and use the Insert Variable option and the button will then use the variable as it's caption. But note that if the variable content is too long for the caption the button will not resize and some content may be lost.

Reset Variables

The most common error beginners make when using variables is forgetting to reset them when necessary and, particularly if the user goes back to the beginning of a publication to restart. Opus provides a Reset All action which helps you set all the variables in a publication back to their initial values.

System Variables

Opus allows you to access key system variables such as the date (SYSTEM_ and time, the version of windows and the user's display mode etc. It also provides

Scoring Variables

Both Opus Pro and Creator automatically keep track of several scoring variables when you use the Score action

Everyday Features

Opus Pro and Opus Creator Reference - Creating and Using Variables