Skip to content

AST Syntax & Data

This page covers the core syntax you use to build AST commands.

The parser understands 5 main prefixes:

PrefixSyntaxPurposeExample
$( $(funcName arg1 arg2)Call a function$(random 10)
%( %(name) or %(name value)Read or write a variable%(wins), %(wins 5)
*( *(condition ? yes : no)Compute logic or math*(5 > 3 ? "yes" : "no")
^( ^(variableName)Check existence^(#wins)
#( #(commandName args...)Call another command#(othercmd arg1)

Variables are created by you. They can be temporary or persistent depending on the prefix you choose.

PrefixStoragePersistencePlanExample
noneMemoryCurrent execution onlyFree%(temp)
#CacheUp to 24 hoursFree%(#wins)
##Cache + user-scopedUp to 24 hoursFree%(##chips)
*DatabasePermanentPremium / Pro%(*wins)
**Database + user-scopedPermanentPremium / Pro%(**rank)
  1. Cache variables expire after about 24 hours.
  2. Expired cache values come back blank, not 0.
  3. Assignment overwrites.
Terminal window
%(#wins 1)

The example above sets the value to 1. It does not add 1.

Terminal window
%(#wins *(%(#wins) + 1))

User-scoped values can target another user:

Terminal window
%(##rank)
%(##rank(&p1))
%(**rank)
%(**rank(&p1))

When a viewer uses a command, their arguments can be accessed with placeholders.

PlaceholderMeaningExample
&p1, &p2, &p3Positional arguments&p1 = first argument
&tAll remaining trailing text&t = everything left
  • &t must come last
  • you cannot create new &pN placeholders after &t
Terminal window
Command: !greet Hello World
Message: Hello &p1 and &p2!
Hello Hello and World!
Terminal window
Command: !echo lots of args here
Message: &p1 &p2 &t
lots of args here
Terminal window
Message: &t &p1
Error: cannot create new &pN after &t

Use double quotes and ${} when you want interpolation inside a string.

Terminal window
"Hello ${$(user)}!"
"You've won ${%(#wins)} times!"

Parentheses define where an expression starts and ends, so a literal ) inside one would close it early. You have three tools to include special characters as plain text:

  1. Balanced pairs just work. Parentheses that open and close inside an expression are kept as text:

    Terminal window
    $(say score (5-3))
    score ( 5 - 3 )
  2. Double quotes protect any text, including unbalanced characters:

    Terminal window
    $(say "quoted :) here")
    quoted :) here
  3. Backslash escapes protect a single character. Use \( \) \[ \] \{ \} \; \? \: and \\:

    Terminal window
    $(say hello \:\))
    hello :)
    %(mood \:\)) %(mood)
    :)
Terminal window
%[item1, item2, item3]
%[1, 2, 3, 4, 5]
SyntaxMeaningExample
%(arr[0])Access by index%(items[0])
%(arr[-1])Access from the end%(items[-1]) = last element
%(arr[random])Random element%(items[random])
%(arr[].length)Array length%(items[].length)
%(arr[] value)Append value%(items[] extra)
%(arr[2] value)Replace by index%(items[2] updated)
Terminal window
%(items[0])
%(items[random])
%(items[].length)
%(items[] extra)
%(items[1] replacement)
%[1, 2, 3][random]
OperatorMeaningExample
== or =Equals%(wins) == 5
!= or <>Not equals%(status) != "offline"
>Greater than%(level) > 3
<Less than%(age) < 18
>=Greater than or equal%(wins) >= 10
<=Less than or equal%(wins) <= 5
~=Contains%(tags) ~= "gaming"
OperatorMeaningExample
+Add*(%(#wins) + 1)
-Subtract*(%(#wins) - 1)
*Multiply*(%(x) * 2)
/Divide*(%(total) / 2)
%Modulo*(%(count) % 10)
OperatorMeaning
+Unary plus
-Negation

These are for loop variables only:

OperatorMeaning
=Assign
++Increment by 1
--Decrement by 1
+=Add and assign
-=Subtract and assign
*=Multiply and assign
/=Divide and assign
%=Modulo and assign

AST uses ternary expressions for branching:

Terminal window
*(condition ? trueValue : falseValue)
*(%(#wins) > 10 ? "Champion" : "Keep trying")
*(%(islive) == 1 ? "Stream is live!" : "Stream is offline")
Terminal window
*(for #i = 0; #i < 3; #i++ {
%(out[] #i)
})
Terminal window
*(for #item in %(#items[]) {
%(result[] %(#item))
})
FunctionPurpose
$(break)Exit the loop immediately
$(continue)Skip the current iteration
PlanMax nesting depthMax iterations
Free225
Premium350
Pro4100
Terminal window
*(for #i = 0; #i < %(#count); #i++ {
%(output[] #i)
})
"Your numbers: ${%(output[])}"

You can run one command from inside another:

Terminal window
#(othercmd arg1 arg2)
  • max recursion depth: 5
  • cycles are detected and blocked
  • referenced output is parsed and substituted back in

Use ^() to ask if something exists:

Terminal window
^(#wins)
^(#items[0])
^(##balance)

This returns true or false.