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

NodeText formRuns
OnStartexport function onStart(ctx)once, when the entity first runs the script
OnUpdateexport function onUpdate(ctx)every frame
OnUiEventexport function onUiEvent(ctx)when the UI element it is attached to gets input

Values

NodeOutputAttributeText form
DeltaTimeNumberctx.deltaTime() (seconds since the last frame)
GetPositionVec3ctx.getPosition()
GetVelocityVec3ctx.getVelocity()
KeyDownBoolkey=ctx.keyDown("Space")
ConstNumberNumber1.50
ConstVec3Vec3ctx.vec3(x, y, z)
AddNumberNumber(a + b)
MulNumberNumber(a * b)
AddVec3Vec3ctx.addVec3(a, b)
ScaleVec3Vec3ctx.scaleVec3(v, s)
GreaterBool(a > b)
EqualBool(a === b)
GetNumberNumbercomponent=ctx.getNumber("DistanceToPlayerSquare")
GetVec3Vec3component=ctx.getVec3("Velocity")
UiClicked · UiHoverEnter · UiValueChanged · UiValueCommittedBoolctx.uiClicked(), …
RerouteNumber / Vec3 / Boolpass-throughtidy 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

NodeInputAttributeText form
SetPositionVec3ctx.setPosition(v)
SetVelocityVec3ctx.setVelocity(v)
SetNumberNumbercomponent=ctx.setNumber("Name", n)
SetVec3Vec3component=ctx.setVec3("Name", v)
AddComponent / RemoveComponentcomponent=ctx.addComponent("Name")
UiCommandcommand=ctx.uiCommand("game.new")

Flow

NodeText form
Branchif (cond) { … } else { … }

More nodes

Newer nodes, by group. Each shows its inputs as pins; the Script Editor's palette (Space) searches them all.

GroupNodes
EventsOnTriggerEnter · OnTriggerExit · OnCollisionEnter · OnCollisionExit (with ContactOther, ContactPoint, ContactNormal) · OnMessage (with MessageIs, MessageValue, MessageSender)
InputActionPressed · ActionReleased · ActionHeld · ActionValue · ActionVector2 · SetActionMapEnabled
Logic & mathsLess · LessEqual · GreaterEqual · NotEqual · And · Or · Not · Min · Max · Abs · Clamp · SubNumber · DivNumber · Time · Every · Random · RandomRange
MemoryGetVar / SetVar (one entity) · GetGlobal / SetGlobal (every script) · GetVarVec3 / SetVarVec3
2DGetPosition2D / SetPosition2D · GetVelocity2D / SetVelocity2D · GetAngle2D / SetAngle2D · Vec2 maths (Vec2Normalize, Vec2Distance, Vec2ToAngle, …)
Other entitiesFindEntity · FindByTag · Get/SetEntityPosition(2D) · Get/SetEntityVelocity(2D) · SendMessage
Physics queriesRaycast2D (+ Raycast2DEntity, …Point, …Normal, …Distance) · OverlapCircle2D · OverlapBox2D (+ …First)
GameSetText · 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
//!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 //! node annotation line, followed by its statement.
  • Data wires come from variable names: n4_out is node 4's output, and using it in node 7's statement wires 4 → 7. Values are named nN_value (value nodes) or nN_out (operators).
  • Exec order is the order of the statements, and if / else blocks are Branch outputs.
  • Lines outside //! region graph are 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.