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.
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.
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.
Opus provides a wide range of Maths fucntions which allow you to perform addition, subtraction and multiplication of numbers.
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.
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.
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.
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
Both Opus Pro and Creator automatically keep track of several scoring variables when you use the Score action
Opus Pro and Opus Creator Reference - Creating and Using Variables