What are Variables?

Simply put – variables store information – that’s it! Creating them is also straightforward. The harder part is working out: (i) what information you want to store; (ii) why you want to store it; (iii) where you want to store it; (v) how you are going to use it. This may seem difficult when you first start using variables but once you have used one variable you will think of lots of reasons why you will want to use them again.

Note:
Opus provides a variety of variable types, such as System variables (i.e. provided by Opus) and your own User variables (i.e. ones that you create) – see Types of Variables for more information.

What are variables?

  1. Variables store information – this information can be text (also known in programming, such as OpusScript, as strings) or numbers.

  2. Variable can contain an initial value – the information stored in a variable is known as a value. When you first create a variable you can give it an initial value, for example, a variable named Score may have an initial value of 0, while a variable named UserName may be left blank (i.e. no initial value), you will let the user fill-in the information for you.

  3. Value of variable can change often – the name of a variable is always constant but the value it contains can change at any time – this is the major benefit of using variables. For example, a variable named Feedback could change for every new question in a quiz – this means you only have to create one variable but it can be used on lots of pages in your publication showing different information.

Using Variables in Opus:

  1. There are many reasons why you will want to use variables in Opus; just some of them are listed below.

  2. User information – users can type information into a Input Text object – this is saved in a variable. You may want to know user details (e.g. name, address, telephone, etc) or comments about your publication.

  3. User selection – objects that users select, such as a more information button could be stored in a variable – you could then show the user information based on the information stored in the variable.

  4. Display on a page – you may want to show information to a user that you have stored in a variable, such as their current score in a quiz, their name on a different page in the publication. The Text object allows you to display the value (i.e. the contents) of a variable on screen.

  5. Decision making – the IF and Else actions allow you to have different branches of actions happen – these actions use variables. For example, if the user answers a question correctly you can show a congratulations message and go to the next question, if the answer is incorrect you can send the user back to a remedial page.

  6. 6Scoring information – you can keep track of a users scores in a quiz using variables. You could have different variables for correct and incorrect answers and another for number of tries and feedback.

  7. Saving information to external files – the Storage actions allow you to store information to the hard disk of a computer or to a floppy disk. In particular it allows you to read and write information into variables, allowing you to permanently store information into a file. This information might be used to track the user’s progress, to store purchases or user details.

  8. Resources displayed in an object – some objects, such as the Image, Slideshow and DocView objects can use a variable to work out the contents (i.e. the resource) they should display. For example, if you enter the name of an image in the Filename box of an Image object it will only display the one image; but if you type in a variable name in the Filename box, you can use the same Image object to display different images based on the current value of the variable.

  9. Make calculations – OpusScript uses variables to work out more complicated math processes than the simple add, subtract, divide and multiply actions in the Programming menu of the Programming tab.

Related Topics:

Types of Variable

Creating Variables

Displaying Variables on a Page

Insert Variable or Expression Dialog

Creating Arrays in Opus

Preset and System Variables - Glossary

Overview of Variable in Opus