Using Variables in an OpusScript

The Set Variable action in the Variables menu of the Programming tab of the Actions dialog allows you to create a Page, Publication or Array variables. Opus also provides a variety of System variables such as SCORE_TOTAL and SYSTEM_CD_DRIVE. Both user-defined variables (e.g. Page variables) and System variables can be used within a Script Object or Script action.

Note:
If you are unfamiliar with the concept of Publication and System variables, please read the topics in the Using Variables in Opus chapter of the main Opus Help file. To open this help file, click on the Contents & Index option in the Help menu at the top of the Opus Editor and search the index for the word Variables.

Using Variables in an OpusScript

  1. Create the variable in your publication as normal. For example, a Text Input box allows you to store the information entered by a user into a variable e.g. UserName.

  2. In a Script Object or a Script action, the name of a variable you have created, as in point 1 above, can be used in your script. To use it in your script, simply type the name of the variable at the point that you need it – that’s it. For example, the variable UserName described in point 1 above could be combined with variables created in OpusScript to create a new variable that is displayed to the user, such as, a welcome message showing just their first name.

  3. You can also change the value of a variable created with the Set Variable action in your script – see Syntax: variables for more information.

Using OpusScript variables in Opus

  1. OpusScript variables that you create in your script can also be displayed to users in the same way as the Page, Publication, Array and System variables. For example, to display a Publication variable to the user you would simply create a Text object on a page and use the Insert Variable or Expression dialog to add a variable to the text box. When the user displays the page, the value (i.e. the contents) of the variable is displayed to the user.

  2. With OpusScript variables you can use the Insert Variables or Expression dialog to show the value of a variable by selecting the Constant Expression option in the dialog and typing the name of the OpusScript variable. When the text box is displayed, the user will see the value of the variable.

Note:
With this method, you can only show a Constant Expression, which means the value always remains the same. In other words, if your value of your OpusScript variable is always changing, the user will not see the updated value – in this case see point 3 below.

  1. Alternatively, an OpusScript variable can be used in your publication by simply adding the OpusScript variable name to your list of variables in the Variables tab of the Publication Properties or Page Properties dialog.

Note:
For example, if you create a Text Input object that saves the information into a Publication variable named UserName, and the user enters the name Mr John Smith, you could extract the first name John from the variable UserName using OpusScript functions. This first name could be stored in an OpusScript variable named FirstName. The final step is to create a new variable in Opus using the New Variable dialog and enter the OpusScript variable name FirstName – this variable can then be inserted into a Text object as described in point 1 above. The value of FirstName is worked out by a script but can now be changed either in the script or by the Set Variable action.

Note:
OpusScript variables that have been declared in a script object (i.e. they begin with the word var) cannot be displayed on a page – see Syntax: variables for more information. However, if you "declare" the variable by setting it as a publication variable then you can access that withint the script object and beyond.

In the main Opus Help file there is a chapter on the types of variables used in Opus. Select Contents & Index from the Help menu at the top of the Opus Editor to open the main Opus Help file. Search for the word Variables in the Index tab and select Types of from the sub menu to find the topic.

Related Topics:

Syntax: Variables