Variables

Usage of arguments and variables in your Streamer.bot actions

Introduction

When a trigger executes an action, it will automatically generate a set of variables specific to that event source and type, and make them available to that action via the argument stack. You can use subsequent sub-actions to populate additional arguments, or even to manipulate existing arguments on the stack.

Arguments only exist within the scope of the current action. Once the action finishes execution, they 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.

Explore all available triggers and their variables in the Triggers API References
Explore all available sub-actions and their variables in the Sub-Actions API References

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.

Using variables within a text field

Using variables within a text field

To replace a variable name with its value from the current argument stack, wrap the variable name with % symbols:

%userName%

Variables are added to the argument stack by each sub-action, which execute sequentially. If you are testing and a variable seems to be missing, ensure that the sub-action which sets it runs before you're attempting to access it!
Read more about how to inspect arguments after an action has executed

Global Variables

Global variables allow you to share data between multiple actions, or even persist it across multiple restarts of Streamer.bot.

To set the value of of a global variable in your action, call the Set Global Variable sub-action
This does not also make the global variable's value available in your action
To access the value of a global variable in your action, you must first assign it to a local variable with the Get Global Variable sub-action

To directly access the value of a persisted global variable, wrap the variable name with ~ symbols:

~myPersistedGlobalVariable~

This syntax currently only works for persisted global variables, and not user global variables.
Read more about how to use the global variable viewer to view all of your global variables in one place!
Read more in API > Sub Actions > Core > Globals

User Global Variables

User global variables function as global variables, but store values per user.

User global variables can be useful for creating per-user counters, leaderboards, or anything you can think of!

Generic

The following variables are always available:

%date%
string
Get the current system date, formatted as yyyy/MM/ddFormatting is supported, e.g. %date:yyyy/MM/dd% or %date:dddd, dd MMMM yyyy%
%time%
string
Get the current system time, formatted as hh:mmFormatting is supported, e.g. %time:HH-mm%
%longtime%
string
Get the current system time, formatted as hh:mm:ss
%unixtime%
long
Get the current system time, represented as unix time, in seconds.Example: 1725936677
%filedatetime%
string
Get the current system time, formatted as yyyyMMdd.hhmmss
%lf%
string
Insert a new line character sequence, \r\n
%actionId%
string
Get the unique ID of the action being executed
%actionName%
string
Get the name of the action being executed
%runningActionId%
string
Get the running ID of the action instance within the queue
%actionQueuedAt%
DateTime
Get the time the action was queued
%__source%
EventType
The EventType which triggered the current action. C# required to access
Read more in API > C# > Enums > Event Type
%eventSource%
EventSource
The EventSource which triggered the current action. C# required to access
Read more in API > C# > Enums > Event Source

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%

Read more about all supported numeric format strings

Date and Time

Similarly, %time% can be formatted in short notation with AM/PM using the following syntax: %time:t%

Read more about all supported date and time format strings

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.

Example
// 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)$
Explore the mXparser documentation for all supported operations

length()

Obtain the length of arbitrary text or a given variable.

Example
// 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.

Example
// Same results as %user%
$parse(user)$

// First, Set Argument %i% to 0
$parse(line%i%)$
// ==> returns value of %line0% (the first line of the file)

// Set Argument %i% to $math(%i% + 1)$ (i.e., 1)
$parse(line%i%)$
// ==> returns value of %line1% (the second line of the file)
%arguments% and ~persistedGlobalVariables~ will be parsed in parse's parameter, but not other $inline()$ functions or formatting. If you wish to use another function, set another argument to the output of the function, and use that argument in parse instead.

Global Variable Viewer

The global variable viewer in Streamer.bot provides a convenient location to view, modify, and create all types of global variables, including per-platform user global variables.

You can open the global variable viewer at any time by clicking Global Variables on the Streamer.bot toolbar: Global Variable Viewer Button

Global Variable Viewer Button

You will be greeted with a popup window: View Global Variables

View Global Variables

Global variables are updated in real-time, making this view extremely useful while you create and test your actions!

Options

Add/Edit Global Variables

Selecting Add or Edit from the context menu will greet you with the following options: Global Variable Viewer Edit Dialog

Global Variable Viewer Edit Dialog

Variable Name
Text required
Enter the name for your new global variable
Value
Text required
Enter a new value for this global variable
Auto Type
Toggle
By default, all values are treated as text, or 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 as int or long
  • true or false can be auto-typed to a bool

Global Variables Context Menu

The Right-Click context menu provides the following options:

Add Variable
Create a new global variable of the current category type (e.g. persisted, non-persisted)
Edit Variable
Edit the selected global variable, see configuration options above
Delete Variable
Remove the selected global variable
Copy Variable Name
Copy the selected global variable name to your clipboard
Delete all Variables
Remove all global variables from the current category type (e.g. persisted, non-persisted)

Inspecting Arguments

Navigate to Action Queues > Action History in Streamer.bot

From the Action History view, you can Right-Click an action execution to inspect all variables from that action's argument stack:

Action History Context Menu

Action History Context Menu

Inspect Variables When Queued
View all variables on the argument stack from before any of the sub-actions had run
Inspect Variables After Run
View all variables on the argument stack from after the action had completed

Variables Dialog

When you select one of these options, you will be greeted with a dialog containing the respective variables:

Action History Variables

Action History Variables

You can use this dialog any time you want to know what variables are populated by a trigger or the sub-actions during a specific run of an action