Variables
Introduction
When a trigger executes an action, it will automatically generate a set of variables specific to that event source and make them available to that action via the argument stack. You can use subsequent sub-actions to populate additional arguments, or even manipulate existing arguments on the stack.
Arguments only persist until the called action finishes execution and can not be referenced by any other action. To share variables across multiple actions, or to persist them across restarts, you can store them as Global Variables.
Types
Arguments
The argument stack contains all local variables accessible by an action and its sub-actions.
These variables can be utilized in most sub-action configuration text fields.
To use a variable from the current argument stack, wrap the variable name with %
symbols:
%userName%
Global Variables
Global variables allow you to share data between multiple actions, or even persist it across multiple restarts of Streamer.bot.
To quickly access a global variable, wrap the variable name with ~
symbols:
~myGlobalVariable~
User Global Variables
User variables function as global variables, but store values per user.
Generic
The following variables are always available:
yyyy/MM/dd
Formatting is supported, e.g. %date:yyyy/MM/dd%
or %date:dddd, dd MMMM yyyy%
hh:mm
Formatting is supported, e.g. %time:HH-mm%
hh:mm:ss
1725936677
yyyyMMdd.hhmmss
\r\n
Formatting
Variables can be formatted inline using standard C# notation
Numbers
For example, to format a numeric variable %tipAmount%
as a currency with 2 decimal places, we can use the following syntax: %tipAmount:c2%
Date and Time
Similarly, %time%
can be formatted in short notation with AM/PM using the following syntax: %time:t%
Inline Functions
Anywhere you can do a variable replacement, you can also execute inline functions to manipulate them.
math()
Leveraging the mXparser library, you can evaluate mathematical equations directly inline with variable replacements.
// Expected output: 20
$math(10+10)$
// Multiply %x% by 1.25
$math(%x% * 1.25)$
// Multiply %tier% by 10
$math(%tier% * 10)$
// Divide %duration% by 1000
$math(%duration% / 1000)$
length()
Obtain the length of arbitrary text or a given variable.
// Expected output: 69
$length(Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi, ut.)$
// Obtain the length of %rawInput%
$length(%rawInput%)$
parse()
Fetches the value of the argument named by parse
's parameter, which itself can be the result of parsing variables. In other words, it lets you "double parse" a value. This is often useful in a While loop to access an array of numbered arguments with an index variable.
// Same results as %user%
$parse(user)$
// First, Set Argument %i% to 1
$parse(line%i%)$
// ==> returns value of %line1% (the first line of the file)
// Set Argument %i% to $math(%i%+1)$ (i.e., 2)
$parse(line%i%)$
// ==> returns value of %line2% (the second line of the file)
%arguments%
and ~persistedVariables~
will be parsed in parse
's parameter, but not other $inline()$
functions. If you wish to use a function, then set another argument to the output of the function, and use that argument in the parse
instead.Variable Viewer
The Variable Viewer in Streamer.bot provides a convenient location to view, modify, and create all types of global variables, including per-platform user variables.
You can open the variable viewer at any time by clicking Variables
on the Streamer.bot toolbar:
You will be greeted with a popup window:
Options
Add/Edit Variables
Selecting Add
or Edit
from the context menu will greet you with the following options:
string
variables.Enable Auto Type
to automatically determine the type for the entered value.For example:0
can be auto-typed to a numeric type such asint
orlong
true
orfalse
can be auto-typed to abool
Variables Context Menu
The context menu provides the following options:
Inspecting Arguments
Action Queues > Action History
in Streamer.botFrom the Action History
view, you can an action execution to inspect all variables on the argument stack:
Variables Dialog
When you select one of these options, you will be greeted with a dialog containing the respective variables: