Set Variable Array

The Set Variable Array is very similar to the Set Variable action, in that it lets you:

(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.

However, there are two differences between the two actions:

(i) The Set Variable Array is one variable with MANY values. A standard Opus variable can only contain one value at a time, while an array is a variable made up of elements and each element can contain its own value.

(ii) Each Set Variable Array action you add allows you to set the new value for one element of an array.

Note:
If you are unfamiliar with arrays, see Creating Arrays in Opus for more information.

Setting up the Set Variable Array action:

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

2. Use the Variable box to select the name of the array that you want to set (i.e. which array 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 array 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 array variable.

Note:
The variables are listed in alphabetical order and only show the array variables. You can only set (i.e. change the value of) one element of an array with each Set Variable Array action, using the element’s Index number.

3. Use the Index option to select the element of the array that you want to set (i.e. change the value of). Use the spin buttons to identify the element of the array variable.

Note:

For example, if you create an array with three elements, the Index position in the array for each element could be 1,2 and 3. If you wanted to set the value of element 2 in your array you would therefore enter the number 2 in the Index box. Note, in programming languages arrays normally start at Index position 0 (i.e. zero); in Opus you can start with 0 or with 1 if you think that would be easier – just remember which number you started from.

4. Use the Text option if you want to type the new value for the element of the array 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.

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

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

Note:
The variable that you copy can be any standard variable not an element from another array variable.

4. Use the Overwrite current contents option when you want to entirely replace the current value of the element of an array variable with the new value you entered in the Editor window. By default, this option is selected. The old value for this variable is lost.

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

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

Related Topics:

Introducing the Variables Actions

Choosing an Action