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

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 use a variable from the current argument stack, wrap the variable name with % symbols:

%userName%

Variables are added onto the argument stack during sequential execution of each sub-action. If you are testing and a variable seems to be missing, ensure that you are testing at the correct point of execution!
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 quickly access a global variable, wrap the variable name with ~ symbols:

~myGlobalVariable~

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

User Global Variables

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

User 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# > Core > Events
%eventSource%
EventSource
The EventSource which triggered the current action. C# required to access
Read more in API > C# > Core > Events

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 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: Variable Viewer Button

Variable Viewer Button

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

View Global Variables

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

Options

Add/Edit Variables

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

Variable Viewer Edit Dialog

Variable Name
Text required
Enter the name for your new variable
Value
Text required
Enter a new value for this 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

Variables Context Menu

The context menu provides the following options:

Add Variable
Create a new variable of the current category type (e.g. persisted, non-persisted)
Edit Variable
Edit the selected variable, see configuration options above
Delete Variable
Remove the selected variable
Copy Variable Name
Copy the selected variable name to your clipboard
Delete all Variables
Remove all 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 an action execution to inspect all variables on the argument stack:

Action History Context Menu

Action History Context Menu

Inspect Variables When Queued
View all variables on the argument stack before the action has started
Inspect Variables After Run
View all variables on the argument stack after the action has 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