Scripts and Flow
OpalScript and Flow share one component registry. Attach the script, then the graph can call it.
Methods that become nodes
| OpalScript | In Flow |
|---|---|
public void Collect() | Component action |
public bool IsSpinning() | Component condition |
public async Task<int> Charge() | Action with Started, Completed, Canceled, Failed paths |
Lifecycle (Start, Update, FixedUpdate, End) | Engine only — not nodes |
Typed parameters become Flow inputs. [Pure] opts a synchronous helper into checked read-only behavior, including transitive calls. An ordinary public bool condition can still run commands.
Public async methods can return Task<T> with typed completion results. Flow uses the same outcomes as the Tasks panel. See task outcomes in Flow and Tasks.
Call a script from Flow
A public void method on an attached class becomes a component action. Engine hooks such as OnTap are not Flow nodes — the high-level coin uses OnTap in the class itself.
class Coin : Component {
public void Collect() {
Game.SetNumber("score", Game.GetNumber("score") + 1);
Scene.Destroy(Self);
}
}After you attach Coin and declare score:
On Tap
→ Coin.CollectCollect adds one to GameState and destroys the object.
Script node
Flow also has a Script node for a one-off snippet (current object, event params, components). Keep those named. A graph full of anonymous blocks is harder than either pure Flow or a reusable project class.
Use a Script node between an event and an action when you are prototyping, then promote it to a class method when you reuse it.
Events
An OpalScript public event Payload Opened appears under that component in Flow, with an aggregate Payload pin and typed member pins. Optional values expose presence separately. [EventId("opened")] keeps the Flow key stable across renames. See typed events.
HUD and UI
Score labels are the easy case: Data bindings → GameState in the UI Inspector. See UI and HUD.
When a label needs a derived number (a percent, a price), expose a [Computed] getter — typed HUD bindings. Buttons that call a method: direct UI actions.
What not to mix up
- UI score labels use Data bindings → GameState. Flow writes GameState with Set Value / Add Counter, or
=GameState.scorein a Flow expression. Scripts useGame.SetNumber("score", …). opal.componentdeclarations are not typedGetComponent<T>()targets. Look up OpalScript classes and native types.- Flow as text is the same graph as nodes — it is not OpalScript.