# Variables in Script

### Using Variables in Script

You can use variables to perform the desired operation.

Note:

- OR/AND/XOR/NOT always returns a 32 bit unsigned integer value.
- When the input value is negative, bit shift expressions return a 32 bit integer value.
- When the input value is positive, bit shift expressions return a 32 bit unsigned integer value.

### Using External Variables in Script

When using external variables in a script, the device address value assigned to the external device may change during script processing.

Using a device address in an assign operation may cause a write delay as the display unit must read the address data from the connected device.

Note: When changing the value of an external variable multiple times in a script with a single trigger, the external variable value will not update immediately.

To use the value of the updated external variable in the triggered script, store the value to an internal variable and use it in the script. Or update the value of the external variable with a different trigger before using the external variable value.

(Example)

Add the following variables.

[Name] | [Data Type] | [Source] | [Device Address] | [Number of Bytes/Words]
Var1 | [INT] | 'Schneider Modbus Serial Equipment' | 400020 | -
Var2 | [INT] | 400021 | -
Var3 | [INT] | 400022 | -

Draw the following objects on the screen.

#### Switch object (Name: Switch1)

No special configuration.

#### Script

Legend | Block
1 | [Triggers] ➞ [Touch] ➞ [Touch]
2 | [Operations] ➞ [Value Change] ➞ [Value Change]
3 | [Values] ➞ [Screen Object]
4 | [Logic] ➞ [Math]
5 | [Values] ➞ [Variable]
6 | [Values] ➞ [Constant]

When Switch1 is pressed, the value of Var1+1 is assigned to Var2. However, the value of Var2 has not been assigned to Var3 because of time-consuming communication with the device.

In such cases, you can program a script in such a way that the result of Var1 is first stored to internal variable Var4 before it is executed as shown in the following example.

Add the following variables.

[Name] | [Data Type] | [Source] | [Device Address] | [Number of Bytes/Words]
Var1 | [INT] | 'Schneider Modbus Serial Equipment' | 400020 | -
Var2 | [INT] | 400021 | -
Var3 | [INT] | 400022 | -
Var4 | [INT] | [Internal] | - | -

#### Script