Variables

Edit

Introduction #

Variables are containers for storing data values (including numbers and strings), that can be reused over and over again.
Variable names are case sensitive, meaning that “Variable” and “variable” are not going to have the same value. Variable name must always start with a letter and must only contain letters, numbers and _.

Watch a detailed video explaining how to use variables in SAMMI #

Global Variables #

All global variables are stored inside global variables object and are accessible from any button at all times. Some of these variables are permanent.
Use Get Global Variable command to get a global variable.
Do not pollute the global namespace unless you absolutely have to. It is always better to use either local or button variables.

Button Variables #

Button variables are stored inside every button object. They can be accessed from any other button (if their own button is set to persistent) by using Get Button Variable command and created or updated by using Set Button Variable command.

Local Variables #

Local variables are button’s own variables that can be directly accessed from its own button at anytime (even if the button is set to non persistent). This is what you want to use 99% of the time.
Using Set String Variable command lets you set a local variable containing text.

Persistent vs. non persistent variables #

By going to your Button Settings, you can decide whether you want your local variables to persist or not for the given button.
If you check the box, it means the variables will be accessible even after the button has finished. If Allow Button Overlap is enabled, all button executions will share the same variables.
If you uncheck the box, the variables will be accessible only when the button is running and only inside their own button. Other buttons cannot access them even if the button is currently running. If Allow Button Overlap is enabled, unique variables will be created for each button execution and will never be shared.

Init Variables #

If you right click on a button, you can edit its initial variables.
These exist to prevent crashes if you have enabled persistent variables.
The window uses a simple JSON format to initialize your variables.
For example, if you want your variable name to have a value of SAMMI and your variable age to have a value of 18 on initilization, you can do:

{
	"name": "SAMMI",
	"age": 18,
}

You can also initiliaze complex variables, such as arrays or objects:

{
	"namesArray": ["Silverlink", "Melonax", "Cyanidesugar"],
	"colorObject": {
		"Silverlink": "blue",
		"Melonax": "purple",
		"Cyanidesugar": "red "
	}

}

Variable types #

Variable Type Example Color in variable window
Real value (number) 50 green
String (text) "My Cat" or 'My Cat' beige
Boolean 1 = true, 0 = false cyan
Array ["cat","rabbit","dog"] yellow
Object {"name": "John", "age": 25, "country": "Canada"} purple
Undefined Variable does not exist/is set to empty value red
Null Variable with empty or non existent reference red

Real value (number)

Variable containing numbers only. Negative values, decimal points and Euler’s numbers are allowed.
Examples: 50, 1.25, -15, 10e+2

String (text)

Variable that contains not just numbers, but also other characters (possibly mixed with numbers).
If you are inserting a string into a YELLOW variable box, you must wrap it in double or single quotes.
Note that a string containing only numbers is not regarded as a number and cannot be used as such. You must use ‘String to Number’ command to convert to number first.
Examples: "Hello world!", 'This is cool', "The tickets cost $50", '50' (still regarded as a string!)

Boolean

In SAMMI, boolean is a number that is either 0 (false) or 1 (true).\

Array

Array is a special variable which can hold more than one value at a time. Learn more about arrays in our Array Introduction section.

Object

Object is another special variables which can hold more than one value at a time. Unlike arrays, objects have named values, key-value pairs. Learn more about objects in our Object Introduction section.

White vs. Yellow Box for parameters #

When you start using commands in SAMMI, you will notice that some parameter boxes have yellow color and some have white color.

Different parameter box colors
Different parameter box colors

It’s extremely important to know the difference as you need to format your input according to the color of the box.

Operation White Box Yellow Box
Inserting another variable You must wrap other variables in /$$/.
/$myVariable$/
You can directly type another variable.
myVariable
Inserting array value You must wrap them in /$$/.
/$myArray[0]$/
You can directly insert them.
myArray[0]
Inserting real values (numbers) You can directly insert them.
26
You can directly insert them.
26
Inserting string values (text) You can directly insert them, such as Hello World and even use new lines by pressing ENTER You have to wrap any string in double/single quotes.
"Hello World" or 'Hello World'
Using a combination of strings and variables You can insert a variable into text by wrapping it in /$$/.
Hello world, this is my /$myVariable$/, isn't it cool?
You must wrap any string in double/single quotes and use + to combine them with other variables. The whole value must be enclosed in parentheses.
( "Hello World, this is my " + myVariable + ", isn't this cool?" )
Math Operations All math operations must be enclosed in /$$/ and parentheses.
Hello world, do you know what's 3+7? It's /$(3+7)$/!
All math operations must be enclosed in parentheses.
( "Hello world, do you know what's 2+7? It's " + (2 + 7) + "!" )


Edit

Set Local Variable #

Creates a new local variable or modifies an existing one.
Supports setting button variables directly to objects/arrays without having to parse and stringify them. This includes setting array values to other objects, too.
Local variables are contained in the button that created them. They can be accessed from other buttons by using Set/Get Button Variable (as long as the button has persistent variables enabled).

Box Name Type Description
Variable Name String Name of the variable.
Operator Dropdown Operator you wish to use on the value.
Variable/Number/String Whatever you want to set the variable value to. Can contain complex math.

Advanced Users
You can use this command to create and modify all variables, including global and button variables, object keys and array items. Lots of commands in SAMMI are redundant and rather targeted at users with no coding knowledge.
Global variables: Use global. prefix, since they’re all stored in an object called global.
Button variables: Use <buttonID>. prefix, since they’re all stored in an object named after the button ID.
Array Values: Use <myArray>[<index>] to change a value inside an array.
Object Keys: Use <myObject>.<key> to change a key inside an object.
You can access nested objects and arrays by using dot notation, it works the same just like in JavaScript. Bracket notation does not work, you must use Set/Get Object Variable command for keys containing spaces or dashes.


Edit

Set String Variable #

Creates a new local variable containing text.
Checking relative will cause it to do string addition. I.e. if a variable myVariable already exists and contains Hello and you enter World in the Text field, myVariable will be now HelloWorld.

Box Name Type Description
Variable Name String Name of the variable.
Relative Checkbox Checked = will be turned into string addition, Unchecked = replaces whatever is currently in the original variable if already populated
Text String Whatever text you want to set the variable to. You can press ENTER to insert a new line.


Edit

Set Button Variable #

Creates a new button variable or modifies an existing one.
Button variables are other buttons local variables.
Supports setting button variables directly to objects/arrays without having to parse and stringify them. This includes setting array values to other objects, too. If you need to set a button variable in non persisten button, please use Set Button Instance Variable command instead.

Box Name Type Description
Button ID String The button you want to set the variable for.
Variable Name String Name of the variable.
Operator Dropdown Operator you wish to use on the value.
Variable/Number/String Whatever you want to set the variable value to, including arrays and objects (2023.2.2 and up). Can contain complex math.


Edit

Set Button Instance Variable #

Functions similarly to the “Set Button Variable” command, but with the added capability of setting a variable within a non-persistent button.
Supports setting button variables directly to objects/arrays without having to parse and stringify them. This includes setting array values to other objects, too.
To use this command, you must provide the instance ID, which is automatically included in an Extension Command as part of the payload (Data.instanceId).
Button instances are ephemeral and are destroyed once the button’s execution is complete. To successfully set a variable within a non-persistent button, the button must still be active at the time the command is executed. If the button has already completed its execution, the instance will be destroyed, and setting the variable will no longer be possible.

Box Name Type Description
Button ID String The button you want to set the variable for.
Button Instance ID String The button instance ID to set the variable in
Variable Name String Name of the variable.
Operator Dropdown Operator you wish to use on the value.
Variable/Number/String Whatever you want to set the variable value to. Can contain complex math.


Edit

Set Boolean #

Allows you to set a boolean variable.
In SAMMI, boolean is a number that is either 0 (false) or 1 (true).

Box Name Type Description
Save Variable As String Name of the variable to save the boolean value.
Boolean Value Boolean Boolean value you want to set the variable to. Will be converted to true or false.


Edit

Get Button Variable #

Gets another button’s variable. The button must have persistent variables enabled, else no other button can access them even if the button is running.

Box Name Type Description
Button ID String The button you want to set the variable for.
Get Variable String Name of the variable to get.
Save Variable As String New local variable name to save the button variable.


Edit

Get Global Variable #

Gets global variable.

Box Name Type Description
Get Variable String Name of the global variable to get.
Save Variable As String New local variable name to save the global variable.

See a list of all premade global variables.


Edit

Get Variable Type #

Returns a string indicating the type of the variable:

  • "number" for numbers
  • "string" for variables containing text
  • "object" for objects
  • "array" for arrays
  • "boolean" for boolean values
  • "undefined" for variables that aren’t defined (do not exist)
  • "null" for null variables (sometimes retrieved from HTTP requests, cannot be manually created)
Box Name Type Description
Save Variable As String Variable to save the result in.
Variable to Check String The variable to get the type of.


Edit

Variable Transition #

Transitions a variable (numbers only) from a starting value to a final value over a given duration.
This command can act as a timer to trigger other commands or buttons.
For example, if you set the start value to 10, final value to 0 and duration to 10000ms (=10 seconds), it will decrease the value by 1 every second and reach 0 after exactly 10 seconds.

Box Name Type Description
Variable Name String Name of the variable.
Start Value Number Starting point (where the counting starts from)
End Value Number Finishing point (where the counting stops at)
Duration(ms) Int Duration of the transition in milliseconds
Allow Decimal Checkbox Whether you want to allow values with decimal points
Smooth Dropdown None = Normal, Out = Starts out fast and ends slow, In = Starts out slow and ends fast, In/Out= Starts out slow, gets faster and then slows down at the end again.


Edit

Delete Variable #

Deletes an existing variable.
You can use dot notation for deleting button variables (buttonID.myVariable), global variables (global.myVariable), object keys (myObject.key).

Box Name Type Description
Variable String Name of the variable to delete. Leave empty or all to delete all button variables.