Si variable create

From Sim Innovations Wiki
Jump to navigation Jump to search


var_id = si_variable_create(variable, type, initial_value)

si_variable_create is used to create a global variable. A global variables can be used to communicate between instruments.

Return value

Argument Type Description
var_id Number This id can be used for further reference. Functions such as si_variable_write can use this var_id. Its good practice to store this var_id in your logic code.


# Argument Type Description
1 variable String Name of the variable
2 type String Data type of the variable, can be INT, FLOAT, DOUBLE, BYTE, BOOL, STRING, INT[n], FLOAT[n], DOUBLE[n] or BYTE[n]
3 initial_value Object Set the initial value for this variable.


-- Create a new variable
var_id = si_variable_create("my_variable", "FLOAT", 1.5)

-- Changed my mind, I want it to be 2.5
si_variable_write(var_id, 2.5)

Example with an array

-- Create a new variable array
var_id = si_variable_create("my_variable", "FLOAT[4]", {1, 3.2, 5, 5.6})

-- Changed my mind, I want the second and third position to be 0.
si_variable_write(var_id, {0, 0}, 2)