AST Syntax & Data
Complete AST syntax reference covering prefixes, variable storage, chat arguments, escaping, arrays, operators, conditionals, loops, deletes, command references, and timers.
Use this page as your syntax lookup when writing AST commands. If you’re just getting started with AST, read the AST overview first.
How a message is read
Section titled “How a message is read”The parser only evaluates chunks that begin with an AST prefix. Everything outside a prefix is sent to chat verbatim, including quotation marks, punctuation, and emoticons.
Hi $(user)! Welcome to "the stream" :)→ Hi Carlos! Welcome to "the stream" :)Once you enter a prefix, different parsing rules kick in:
- Each prefix stays open until its matching closing
). - Double quotes,
${ }interpolation, and%[ ]literal arrays only work inside a prefix.
Core prefixes
Section titled “Core prefixes”The AST parser recognizes 6 prefixes:
| Prefix | Syntax | Purpose | Example |
|---|---|---|---|
$( | $(funcName arg1 arg2) | Call a function | $(random 10) (a number from 0 to 9) |
%( | %(name) or %(name value) | Read or write a variable | %(wins), %(wins 5) |
%del( | %del(name) | Delete a variable or a list entry | %del(wins) |
*( | *(condition ? yes : no) | Run math, logic, or a loop | *(5 > 3 ? "yes" : "no") |
^( | ^(name) | Check if a variable or slot exists | ^(#wins) |
#( | #(commandName args...) | Trigger another command | #(othercmd arg1) |
Variables and storage
Section titled “Variables and storage”Variables only exist once you create them, and the prefix in front of a variable’s name controls where it’s stored and how long it survives.
| Prefix | Storage | How long it lasts | Plan | Example |
|---|---|---|---|---|
| none | Memory | Only for the current command run | Free | %(temp) |
# | Cache | 24 hours after the last write | Free | %(#wins) |
## | Cache, per viewer | 24 hours after the last write | Free | %(##chips) |
* | Database | Permanent | Premium / Pro | %(*wins) |
** | Database, per viewer | Permanent | Premium / Pro | %(**rank) |
Storage eligibility follows the streamer’s plan, not the viewer’s.
Important behavior
Section titled “Important behavior”- Writing to a
#or##variable resets its 24-hour clock. Simply reading it does not refresh the timer. - Reading an expired or never-set variable returns blank, not
0. - Writing always overwrites the existing value:
%(#wins 1)sets the value to1instead of adding 1. - On Free, writes to
*and**variables are silently ignored with no error message.
%(#wins 1)The snippet above sets the value to 1—it does not increment it by 1.
Correct increment pattern
Section titled “Correct increment pattern”%(#wins *(%(#wins) + 1))Per-viewer variables
Section titled “Per-viewer variables”## and ** variables store a separate value for each viewer. Without a selector, they target whoever ran the command. To read or write another viewer’s value, pass their login in parentheses right after the variable name (an optional leading @ is accepted).
%(##rank)%(##rank(&p1))%(**rank)%(**rank(&p1))Arguments
Section titled “Arguments”Words typed by a viewer after the command name are exposed through placeholders, starting at word 1 right after the command.
| Placeholder | Meaning | Example |
|---|---|---|
&p1, &p2, &p3… | Word number 1, 2, 3… | &p1 = first word |
&t | Everything after the highest numbered word | &t = the rest of the message |
- Any missing word resolves to blank text.
&tcaptures everything following the highest&pNused earlier in the template.- Reusing an already-used
&pNafter&tis allowed, but introducing a new&pNafter&tfails with[Parser error: cannot create new &pN after &t]. - Viewer input in chat commands is always treated as plain text and can never execute AST code.
Examples
Section titled “Examples”Command: !greet Hello WorldMessage: Hello &p1 and &p2!→ Hello Hello and World!Command: !echo lots of args hereMessage: &p1 &p2 &t→ lots of args hereMessage: &t &p1→ [Parser error: cannot create new &pN after &t]Text in quotes
Section titled “Text in quotes”Inside any prefix, double quotes group text into a single string argument. Wrap expressions in ${ } to interpolate values inside quoted text.
%(greeting "Hello ${$(user)}!")%(greeting)→ Hello Carlos!Any valid AST expression works inside ${ }, such as ${%(#wins)}. To put a literal double quote inside a quoted string, escape it as \".
Escaping
Section titled “Escaping”When you need special characters treated as ordinary text inside a prefix, you have three options:
-
Balanced pairs work. Any
(matched with a)inside a prefix stays literal text.Terminal window $(upper score (5-3))→ SCORE ( 5 - 3 ) -
Quotes protect text. Everything wrapped in double quotes is preserved as text, even unbalanced symbols.
Terminal window $(upper "quoted :) here")→ QUOTED :) HERE -
A backslash protects one character. Escape individual characters with
\(\)\[\]\{\}\;\?\:and\\.Terminal window $(upper hello \:\))→ HELLO :)%(mood \:\)) %(mood)→ :)
To print an AST prefix literally without triggering evaluation, put a backslash before its $, %, *, #, or ^—for example, \$(user) prints $(user) and 100\% prints 100%.
Arrays
Section titled “Arrays”Lists let a variable hold multiple items that you can read, update, remove, and count.
Adding and reading lists
Section titled “Adding and reading lists”%(items[] extra)%(items)→ ["extra"]Reading the whole list prints it as JSON, such as ["a","b"].
Literal lists
Section titled “Literal lists”Literal lists let you write items inline inside a prefix. Assign them with [] to append their items to a list variable—a plain assignment without [] stores the items as one comma-separated string rather than a list.
%(colors[] %[red, green, blue]) %(colors)→ ["red","green","blue"]
%(pick %[1, 2, 3][random]) %(pick)→ 2 (a random 1, 2, or 3)Accessors
Section titled “Accessors”| Syntax | Meaning | Example |
|---|---|---|
%(arr[0]) | Item at an index, starting from 0 | %(items[0]) |
%(arr[-1]) | Item counted backward from the end | %(items[-1]) = last item |
%(arr[random]) | Random item from the list | %(items[random]) |
%(arr[].length) | Total number of items | %(items[].length) |
%(arr[] value) | Append a new item to the end | %(items[] extra) |
%(arr[2] value) | Overwrite the item at a specific index | %(items[2] updated) |
%del(arr[1]) | Delete the item at a specific index | %del(items[1]) |
%del(arr[]) | Empty the entire list | %del(items[]) |
Reading an out-of-range index returns blank, and trying to overwrite an index that doesn’t exist does nothing.
Examples
Section titled “Examples”%(items[0])%(items[random])%(items[].length)%(items[] extra)%(items[1] replacement)%(pick %[1, 2, 3][random]) %(pick)Operators and expressions
Section titled “Operators and expressions”Comparison
Section titled “Comparison”When both sides are numbers, they compare numerically; otherwise they compare as text. Every comparison evaluates to true or false.
| Operator | Meaning | Example |
|---|---|---|
== or = | Equal (text comparison ignores case) | %(wins) == 5 |
!= or <> | Not equal (text comparison ignores case) | %(status) != "offline" |
> | Greater than | %(level) > 3 |
< | Less than | %(age) < 18 |
>= | Greater than or equal | %(wins) >= 10 |
<= | Less than or equal | %(wins) <= 5 |
~= | Contains substring, ignoring case | %(tags) ~= "gaming" |
Arithmetic
Section titled “Arithmetic”| Operator | Meaning | Example |
|---|---|---|
+ | Add | *(%(#wins) + 1) |
- | Subtract | *(%(#wins) - 1) |
* | Multiply | *(%(x) * 2) |
/ | Divide | *(%(total) / 2) |
% | Remainder | *(%(count) % 10) |
- Dividing or taking a remainder by
0evaluates to0instead of throwing an error. - Math operators read any leading number from text (so
5abccounts as5, while text with no leading number counts as0). Comparisons require the entire value to be numeric. - Numeric results are rounded to 6 decimal places.
Unary operators
Section titled “Unary operators”| Operator | Meaning |
|---|---|
+ | Unary plus |
- | Negation |
Loop-variable assignment operators
Section titled “Loop-variable assignment operators”These operators work exclusively on loop variables such as #i. See Loops.
| Operator | Meaning |
|---|---|
= | Assign |
++ | Increment by 1 |
-- | Decrement by 1 |
+= | Add and assign |
-= | Subtract and assign |
*= | Multiply and assign |
/= | Divide and assign |
%= | Remainder and assign |
Conditionals
Section titled “Conditionals”Use a ternary inside *(...) to pick between two outcomes:
*(condition ? trueValue : falseValue)*(%(#wins) > 10 ? "Champion" : "Keep trying")*(%(islive) == 1 ? "Stream is live!" : "Stream is offline")A condition evaluates as false if its value is empty, 0, or false. Everything else counts as true.
Reference a loop variable directly without %( ), such as #i. Writing %(#i) looks up a cache variable named i instead of the loop counter.
Range loop
Section titled “Range loop”*(for #i = 0; #i < 3; #i++ { %(out[] #i) }) %(out[])→ ["0","1","2"]Foreach loop
Section titled “Foreach loop”%(items[] a) %(items[] b) *(for #item in %(items[]) { %(result[] #item) }) %(result[])→ ["a","b"]Foreach loops also accept literal lists directly: *(for #c in %[red, green] { ... }).
Loop control
Section titled “Loop control”| Function | Purpose |
|---|---|
$(break) | Stop the loop immediately |
$(continue) | Skip the rest of the current pass and move to the next |
*(for #i = 0; #i < 4; #i++ { *(#i == 2 ? $(continue) : "") %(o[] #i) }) %(o[])→ ["0","1","3"]Plan limits
Section titled “Plan limits”| Plan | Loops nested inside each other | Passes per loop |
|---|---|---|
| Free | 2 | 25 |
| Premium | 3 | 50 |
| Pro | 4 | 100 |
Any loop nested deeper than your plan’s limit is skipped, and loops stop once they hit their pass cap.
Loop example
Section titled “Loop example”%(count 3) *(for #i = 0; #i < %(count); #i++ { %(output[] #i) }) %(output[])→ ["0","1","2"]Delete
Section titled “Delete”%del(...) removes a variable or clears part of a list without outputting text.
%(list[] a) %(list[] b) %(list[] c) %del(list[1]) %(list[])→ ["a","c"]
%del(wins)%del(name) deletes the variable along with any list stored in it, %del(name[0]) removes a single index, and %del(name[]) clears every entry in the list. Per-viewer variables support selectors here as well: %del(##rank(&p1)).
Exists checks
Section titled “Exists checks”Check whether a variable or list entry exists with ^(), which returns true or false.
^(#wins)^(#items[0])^(##balance)Command references
Section titled “Command references”Trigger another custom command from inside your reply with #(...):
#(othercmd arg1 arg2)Any words after the command name are passed along as its arguments. The reference itself outputs nothing in the outer message.
- Command references can nest up to 5 levels deep.
- A command cannot appear twice in the same call chain, blocking infinite loops.
- One message can trigger up to 50 total references across all levels.
- The outer message posts first. Sibling references then execute in written order, with each reference’s nested calls finishing before moving to the next sibling.
- Every referenced command posts its own chat message, and its output is not re-parsed as AST.
- If a referenced command can’t run—for instance, because it’s disabled or on cooldown—it is simply skipped.
Scheduled timers
Section titled “Scheduled timers”$(timer seconds message_and_actions) schedules its body to run after a delay. The command itself finishes immediately, and the scheduled body runs once the timer fires.
$(timer 300 "Five minutes are up!" $(trigger.send airhorn))- Delays must fall between
1and604800seconds (seven days). - Scheduled timers are only available in Twitch channels.
- Every call creates an independent timer that runs at most once.
- Saved timers survive bot restarts. If the bot is offline when a timer is due, it still runs as long as it is within a 10-minute grace period; at or past 10 minutes late, it expires. A crash right after a timer is claimed can lose the action, so execution is not guaranteed.
- Timers can schedule other timers up to five levels deep.
- Each channel can hold up to 100 pending timers at once. Scheduling can also fail at the shared 10,000-timer cap, if the saved job exceeds 64 KiB, or if cache storage fails, returning
timer: could not schedule timer.
Timer errors print inline starting with timer:, such as timer: seconds must be between 1 and 604800.