Run Variables
Pass a value from one Action to later steps.
A Run is one execution of an Action list, top to bottom. Run Variables are how one step passes something to a later one: an Action returns a value, and the steps after it can read it.
They live for exactly that Run. Nothing persists, and two overlapping Runs never see each other's values.
Declare, return, reference
Declare it
{
"actions": [
{
"name": "Switch Scene",
"type": "switch-scene",
"produces": [
{ "key": "previousScene", "name": "Previous scene", "type": "string" }
]
}
]
}name is what users see in the picker. type is one of "string", "number",
or "boolean" — there are no object or array Run Variables.
Return it from onTrigger
async onTrigger(ctx: StandaloneTriggerContext<Settings>) {
const previous = await obs.currentScene();
await obs.switchTo(ctx.settings.scene);
return { previousScene: previous };
}The user references it
In a later step's settings, a JSON source expression goes in double braces:
{{{"type":"source","group":"obs","action":"switch-scene","key":"previousScene","args":{}}}}The expression carries the plugin's name as group, the producing Action's
type as action, and the variable's key. A later If/Else can also branch on it
directly, picking it from a list rather than typing anything.
What gets dropped
Fluxta validates every returned value against the declaration and drops what does not fit:
- a key that is not in
produces[] - a value that is not a string, number, or boolean
- a value whose type disagrees with the declared
type - everything, if the Action declares no
produces[]at all
Each drop is logged as a warning by the app, not reported back to the plugin. A
Run Variable that never shows up is therefore almost always a mismatch between
what was declared and what was returned — a number declared as "string", or a
key renamed in one place only.
Reading references
When an Action's settings contain a reference, it is already resolved by the
time onTrigger sees them. Nothing needs parsing and nothing needs opting into:
import { serializeExpression } from "@fluxta/sdk/api";
const user = serializeExpression({
type: "source", group: "twitch", action: "chat-message", key: "user", args: {},
});
// saved: { message: `hi ${user}!` }
// arrives: ctx.settings.message === "hi alice!"A setting that consists of exactly one reference keeps the value's scalar type.
For example, a reference to a numeric result arrives as 42, rather than
"42". A reference mixed with text becomes a string, such as "count: 42".
Whitespace outside the reference counts as text.
Substitution walks nested objects and arrays, so any settings shape works. A value containing no reference or template escape arrives unchanged.
A reference to something that was never produced resolves to an empty string. It is never an error, and the Action still runs. If a setting arrives empty when a value was expected, check that the producing Action really runs before this one in the user's list.
Invalid or unfinished expressions remain as written. TemplateField reports
them so the user can fix the text. To include a literal opening delimiter, write
\{{; write \\ for a literal backslash. Other backslashes remain unchanged.
Arguments and substituted values are never expanded as templates.
Values from an automation
Inside an Event's Action list, the Event's own
fields are readable the same way. The expression's action is the Event Source's type:
{{{"type":"source","group":"twitch","action":"chat-message","key":"user","args":{}}}}Most references users write pull something out of the event that fired.
Values the user keeps
A Run Variable is gone when the run ends. A value that has to outlive it — the id of a message posted when a stream started, needed again to edit that message when the stream ends — lives in a Global Variable the user manages in the app, and a template reads it the same way:
{{{"type":"source","group":"variables","key":"3f2a9c1e-…","args":{}}}}The address holds the Variable's id, not its name, so renaming the Variable keeps the reference working; the picker below lists every Global Variable by name, so nobody types the id. The value is the one current when the Action runs, and a reference to a deleted Variable resolves to an empty string, like any other absent reference.
Give users a picker
Users should not have to memorise addresses. Fluxta works out which variables are readable at an Action's position and pushes the list to its editor.
The quickest route is TemplateField from the
UI Kit, a text field with the
picker already built in:
<TemplateField
id="message"
label="Message"
value={message}
onChange={setMessage}
editor={editor}
/>Its menu also offers the other Value Sources available here, including plugin queries. Sources with parameters open an arguments dialog, and each inserted chip can be configured separately. Every source uses the same JSON expression format.
To build a custom picker, use editor.getTemplateSources() and
editor.onTemplateSourcesChange(), and create expressions with
serializeExpression. See the Editor reference.