SetVariable (beta feature)#

This command modifies a robot variable. The modification persists even after a reboot.

A variable’s value can only be changed to a value of the same type. For example, a variable holding a number cannot be assigned a string or an array.

No automatic conversion is performed between supported types. For instance assigning an integer to a boolean value, or vice versa, is not supported.

To change a variable’s type, use the ‘override’ option in the CreateVariable command.

For more information, see Variable management commands (beta).

Syntax#

SetVariable(name, value)

Arguments#

  • name:

    • The name of the variable to modify (e.g., “myVar”).

  • value:

    • The new value to assign to the variable;

    • The value can be any basic JSON type: boolean, number, string, or array (but not a JSON object). Remember that in JSON syntax, boolean values must be lowercase (i.e., true or false);

    • SetVariable will fail with error [1554] if you try to assign a value of a different type or array length.

    • Examples:

      • a boolean: SetVariable(myBoolVar, true)

      • a number: SetVariable(myIntVar, -0.153)

      • a string: SetVariable(myStringVar, "Hello world!")

      • an array: SetVariable(myArrayVar, [190.0, 0.0, 308.9, 0, 90, 0])

Responses#

  • [2554] [name, value]

  • [1554] [errorMsg]

    • errorMsg:

      • An error message explaining why the variable modification failed;

      • e.g., “Cannot set variable my_var (not found)”.

Usage restrictions#

This command can be executed in any robot state.

Cyclic protocols#

See Managing variables with cyclic protocols.