Set Variable Action

image\Action_Variable_Set.jpg

The Set Variable action allows you to specify the content of a variable. In particular, this action allows you to:

(i) Create a new variable and tell the publication it is now available for use and to give it a value at that point.

(ii) Change the value of a variable that already exists.

Note:
Variables store information while the user is running a publication. If you want to store the contents of a variable permanently on the user’s computer you will have to write them to the disk – see Write to Disk File action for more information.

Setting up the Set Variable action:

1. Add the Set Variable action to your trigger, as described in adding actions. The Set Variable tab will automatically appear when you add the action.

2. Use the Variable box to select the variable that you want to set (i.e. which variable you want to change the value of). Click on the down arrow to the right of the Variable box to list all of the variables in the current publication. Alternative, click on the New… button to open the New Variable dialog box in which you can create a new variable.

Note:
The variables are listed in alphabetical order. You can only set (i.e. change) one variable with each Set Variable action.

3. Use the Text option if you want to type the new value for the variable. Click once inside the box and then begin typing – you can add alphabetic, punctuation and numeric characters in the text box. By default this option is selected.

Note:

The text typed into this box is plain text i.e. it cannot be formatted. However, if you are going to display this text to a user in a Text object on the page, you can format the Text object as normal.

If you want to create a new line in the Text box, then press Shift+Enter.

4. Use the Number option if you want the value of the variable to be a number. Type the number in the Number box or use the spin buttons to set a specific number.

Note:

There are other actions in the Variables menu that allow you to add, subtract, multiply or divide the value of a variable with a number – the Set Variable action is used when you simply want to store a number in the variable.

5. Use the Variable option if you want to copy the current value of a variable into this variable (i.e. the variable you entered in point 2 above). This is an often-used option because of its flexibility.

6. Use the Overwrite current contents option when you want to entirely replace the current value of a variable with the new value you entered in the Text, Number or Variable option. By default, this option is selected. The old value for this variable is lost.

7. Use the Add to existing contents if you want to append to the end of the current value of the variable you selected in the Variable box (see point 2 above).

8. Click on the Apply button to save your changes.

Note:
As well as the Set Variable action, Opus provides an action: to set the value of a variable to an OpusScript expression; and to set the values of a variable array – see Set Variable to Expression and Set Variable Array for more information.

Related Topics:

Introducing the Variables Actions

Choosing an Action