Creating Variables

Creating a variable in Opus is done by filling-in the New Variable dialog. This allows you to create all three types of user-defined variables: Page, Publication or Array variables – see Types of Variables for more information.

Sooner or later you will want to use variables for some reason in your publication, if you don’t yet know why you may want to use variables – see What are Variables? for more information.

Note:
If you want to create a variable in OpusScript you declare them by typing a line similar to the following:

var chosenColour="Black"

This create the variable chosenColour and gives it an initial value black is equivalent to creating a New Variable as detailed below but it is only visible to the script which contains it. For further details see OpusScript Variables in Types of Variables.

 

Creating a Variable:

  1. There are several different ways of opening the New Variable dialog, which is used to create new variables:

  1. Type the name of the new variable in the Name box. The name cannot include spaces or special characters other than the underscore (i.e. the _ symbol). You can use numbers and letters in upper, lower or mixed case. For example, the following are all valid variable names:

  userName User_Name Tel_1 Joe99

Note:
Try and make the variable name as descriptive as possible, so you know what it contains. Names such as var1, var2, etc. are meaningless and you will quickly forget what they contain.

Each new variable must have a unique name.

  1. Use the Publication Variable option to create a Publication variable that is available on every page of your publication – see Types of Variables for information about Publication variables.

  2. Use the Page Variable option to create a Page variable that is only available on the page it was created on – see Types of Variables for information about Page variables.

  3. Array variables can be either Publication or Page variables – it simply means that you can hold more than one bit of information in an Array

  4. Use the Initial Value panel to set the contents (i.e. the value) of your new variable when it is created. Some variables you create will want to have an initial value, for example, a variable named quizScore used to store the users score in a quiz can be initially set to 0. Other variables may not require initial values, for example, a variable named User_Name does not need an initial value, you will let the user provide that information for you.

Note:
If you use the Reset All Variables action, the selected variables will again show their Initial Value – see Reset All Variables action.

When the publication is closed, the variables are reset to their Initial Value when the publication is re-opened.

The Initial Value remains the value of the variable until one of the Set Variable actions is used or the value is changed in an OpusScript.

  1. Use the Text option in the Initial Value panel if you want to type in text as the initial value for this variable. You can add as much text as you like, one word, a phrase or paragraphs.

Note:
The text entered in the box will automatically wrap at the end of the line. Press Ctrl+Enter to enter a new line. If you press the Enter key only – this will save the new variable and close the dialog.

  1. Use the Number option in the Initial Value panel if you want to enter a number as the initial value for this variable. Use the spin buttons to set the number, alternatively type the number directly into the box.

Note:
The number can be any length and include decimal points.

  1. Use the Array option in the Initial Value panel if you want to make this an Array variable – that is the variable can contain more than one value at a time.

Note:
To add the values to an Array variable – see Set Variable Array action for more information.

  1. Tick the Persistent option if you want the value of the Page variable to be kept when the user moves to a new page in your publication. If the option is not ticked, when the user moves to a new page in your publication, the current value of the Page variable is reset to the Initial Value you enter here. By default, the option is not ticked.

Note:
This option only applies to Page variables.

  1. Click on the OK button to save your changes.

Related Topics:

What are Variables?

Types of Variable

Displaying Variables on a Page

Insert Variable or Expression Dialog

Creating Arrays in Opus

Preset and System Variables - Glossary