Skip to content

Steps script functions

Functions for C# (Cb.Call) and Python (a cb method each, or cb.call). See Script functions for how to use them.

A Run Python code step in the action editor

steps.check

Checks a condition the same way the If step does: the same comparisons, numbers compared as numbers, and capital letters do not matter. %variables% in both values are filled in first.

Value In Python What to put in
left left The value to look at, like "%user%".
operator operator How to compare, like "equals", "contains", "greater than", "matches regex", "exists" or "does not exist".
right right What to compare with, like "5".

Gives back: true when the condition holds, otherwise false.

var answer = await Cb.Call("steps.check", new Dictionary<string, object?> { ["left"] = "%rawInput%", ["operator"] = "contains", ["right"] = "hello" });
answer = cb.steps_check(left="%rawInput%", operator="contains", right="hello")

steps.pick

Picks one choice at random, where a bigger weight means a bigger chance, like a Group set to "Run one random step".

Value In Python What to put in
weights weights One weight per choice, like [1, 3]: the second is three times as likely. 0 is never picked (unless all are 0).

Gives back: The position of the picked choice: 0 for the first, 1 for the second, and so on. -1 when the list is empty.

var answer = await Cb.Call("steps.pick", new { weights = new object?[] { 1, 3 } });
answer = cb.steps_pick(weights=[1, 3])

steps.run

Runs one step, exactly like it would run in the action editor. Its settings can use %variables% and ~globals~; they are filled in first. Code made with "Export to code" uses this for every step. Steps that hold other steps (Group, Switch, While, Run at the same time) need steps.runList instead.

Value In Python What to put in
type type The step's id, like "core.log" or "obs.setScene". The Sub-actions reference shows the id of every step.
parameters parameters The step's settings by name, like {"message": "Hi %user%"}. Settings you leave out use their usual default.

Gives back: An object: outcome is "completed", or "stop" when the step stopped the action; branch is the path a step with paths picked (like "True"), or null.

var answer = await Cb.Call("steps.run", new { type = "core.log", parameters = new { message = "Hello %user%" } });
answer = cb.steps_run(type="core.log", parameters={"message": "Hello %user%"})

steps.runList

Runs a list of steps in order, with the steps inside them (the True/False paths of an If, the lanes of Run at the same time, and so on), exactly like the action editor would.

Value In Python What to put in
steps steps The steps, written the way actions.json stores them: each one has a type, its parameters and, for steps that hold others, branches (like {"Lane 1": [ ... ]}).

Gives back: How the list ended: "completed", "stop" (a step stopped the action), "break" or "continue" (a Loop break or Loop continue step ran).

var answer = await Cb.Call("steps.runList", new { steps = new object?[] { new { type = "core.log", parameters = new { message = "One" } }, new { type = "core.log", parameters = new { message = "Two" } } } });
answer = cb.steps_run_list(steps=[{"type": "core.log", "parameters": {"message": "One"}}, {"type": "core.log", "parameters": {"message": "Two"}}])