Logic & UI
Script node reference
Every node available in .tgscript visual scripts, with its pins, attributes and text form.
Pin types: Number (a float), Vec3 (x, y, z), Bool. Exec pins (white) are in and
next; a Branch has then and else.
Events
| Node | Text form | Runs |
|---|---|---|
| OnStart | export function onStart(ctx) | once, when the entity first runs the script |
| OnUpdate | export function onUpdate(ctx) | every frame |
| OnUiEvent | export function onUiEvent(ctx) | when the UI element it is attached to gets input |
Values
| Node | Output | Attribute | Text form |
|---|---|---|---|
| DeltaTime | Number | ctx.deltaTime() (seconds since the last frame) | |
| GetPosition | Vec3 | ctx.getPosition() | |
| GetVelocity | Vec3 | ctx.getVelocity() | |
| KeyDown | Bool | key= | ctx.keyDown("Space") |
| ConstNumber | Number | 1.50 | |
| ConstVec3 | Vec3 | ctx.vec3(x, y, z) | |
| AddNumber | Number | (a + b) | |
| MulNumber | Number | (a * b) | |
| AddVec3 | Vec3 | ctx.addVec3(a, b) | |
| ScaleVec3 | Vec3 | ctx.scaleVec3(v, s) | |
| Greater | Bool | (a > b) | |
| Equal | Bool | (a === b) | |
| GetNumber | Number | component= | ctx.getNumber("DistanceToPlayerSquare") |
| GetVec3 | Vec3 | component= | ctx.getVec3("Velocity") |
| UiClicked · UiHoverEnter · UiValueChanged · UiValueCommitted | Bool | ctx.uiClicked(), … | |
| RerouteNumber / Vec3 / Bool | pass-through | tidy long wires |
KeyDown accepts the keys A–Z, 0–9, Space, Escape, Enter, Tab,
Backspace, Delete, the arrow keys, and left/right Shift, Control and Alt.
Actions
| Node | Input | Attribute | Text form |
|---|---|---|---|
| SetPosition | Vec3 | ctx.setPosition(v) | |
| SetVelocity | Vec3 | ctx.setVelocity(v) | |
| SetNumber | Number | component= | ctx.setNumber("Name", n) |
| SetVec3 | Vec3 | component= | ctx.setVec3("Name", v) |
| AddComponent / RemoveComponent | component= | ctx.addComponent("Name") | |
| UiCommand | command= | ctx.uiCommand("game.new") |
Flow
| Node | Text form |
|---|---|
| Branch | if (cond) { … } else { … } |
More nodes
Newer nodes, by group. Each shows its inputs as pins; the Script Editor's palette (Space) searches them all.
| Group | Nodes |
|---|---|
| Events | OnTriggerEnter · OnTriggerExit · OnCollisionEnter · OnCollisionExit (with ContactOther, ContactPoint, ContactNormal) · OnMessage (with MessageIs, MessageValue, MessageSender) |
| Input | ActionPressed · ActionReleased · ActionHeld · ActionValue · ActionVector2 · SetActionMapEnabled |
| Logic & maths | Less · LessEqual · GreaterEqual · NotEqual · And · Or · Not · Min · Max · Abs · Clamp · SubNumber · DivNumber · Time · Every · Random · RandomRange |
| Memory | GetVar / SetVar (one entity) · GetGlobal / SetGlobal (every script) · GetVarVec3 / SetVarVec3 |
| 2D | GetPosition2D / SetPosition2D · GetVelocity2D / SetVelocity2D · GetAngle2D / SetAngle2D · Vec2 maths (Vec2Normalize, Vec2Distance, Vec2ToAngle, …) |
| Other entities | FindEntity · FindByTag · Get/SetEntityPosition(2D) · Get/SetEntityVelocity(2D) · SendMessage |
| Physics queries | Raycast2D (+ Raycast2DEntity, …Point, …Normal, …Distance) · OverlapCircle2D · OverlapBox2D (+ …First) |
| Game | SetText · SetTextNumber (UI text) · PlayAudio · StopAudio (an entity's Audio Source) · LoadScene · CameraFollow2D |
Pins named entity, element, camera or target mean "this entity" when nothing is wired to
them. SetText, PlayAudio and LoadScene take effect at the end of the frame.
Attributes and components
component= names a component by its short name, for example DistanceToPlayerSquare,
Velocity or Position. If a component has several fields, name one: Name.field. The
compiler refuses, with a message, any component that doesn't exist, has no value (a tag), or
is stored in a format scripts can't touch.
The text format
//!tgscript v1
//! script name=MyScript
//! region graph
//! node <id> <NodeType> pos=(x,y) [attribute=value]
export function onUpdate(ctx) {
...one statement per node...
}
//! endregion- Each node is one
//! nodeannotation line, followed by its statement. - Data wires come from variable names:
n4_outis node 4's output, and using it in node 7's statement wires 4 → 7. Values are namednN_value(value nodes) ornN_out(operators). - Exec order is the order of the statements, and
if / elseblocks are Branch outputs. - Lines outside
//! region graphare free-form comments that the editor keeps.
This format is designed so that a person or an AI can write a script in a text editor and paste it into the Text tab. See Authoring scripts with AI.