Skip to content

Your first graph script

A graph script is a script made of steps joined by wires. It lives in an .ograph file. This page makes one that prints a number when its entity starts, then sends a signal.

The class reference for the script is GraphScript.

  1. Open the Graph tab at the top of the editor.
  2. Open the File menu on the tab and choose New….
  3. Set Name to counter. Leave Extends on Entity and Folder on res://. Choose Create.

Check: counter.ograph opens in a tab above the canvas. The Extends class is the base type of the script.

  1. Open the 3D tab and select an entity in the Scene panel.
  2. In the Inspector, choose Attach a script.
  3. Choose Graph, pick counter.ograph and choose Attach.
  4. Save the scene with Cmd+S.

Check: the Script row in the Inspector names counter.ograph.

  1. Go back to the Graph tab. In Variables, choose +.
  2. Set Name to amount, Type to int and Default to 3. Turn on Show in the Inspector, then choose Add.
  3. In Functions, open the Override a virtual list and choose _start. The engine calls _start once, when the entity starts.

Check: _start opens on the canvas with an Entry step.

Press Space on the canvas to open the step list. Type part of a name, move with the arrow keys and press Enter to add the step. Shift+Enter adds it and joins it to the selected step.

  1. Select the Entry step. Press Space, type print and press Shift+Enter.
  2. Drag the amount row from Variables onto the canvas. This adds a Get step for that variable.
  3. Drag from the Get step’s value pin to the Print step’s text pin.

Check: one wire runs from the Entry step’s then to the Print step’s run. A second runs from value to text. Draw a missing wire by dragging from one pin to the other.

A flow wire says which step runs next. A data wire carries a value. Click a step to see it in the Step panel. An input with no wire shows a box for its value. Values are written the way the engine writes them, so text has quotes.

If a wire is refused, the reason shows on the canvas and nothing changes. When a value does not fit an input, the canvas says so and offers a Convert step.

  1. Save the graph with Cmd+S.
  2. Choose Run the project at the top right, or press Cmd+B.

Check: the Output panel shows 3.

In Variables, set the default box of the amount row to 10. Save and run again. The Output panel shows 10.

  1. In Signals, choose +. Rename the new row to amount_shown.
  2. Drag the row onto the canvas. This adds an Emit step with its signal set to "amount_shown".
  3. Drag from the Print step’s then to the Emit step’s run.

Check: the Connections panel lists the Emit step under amount_shown.

Anything connected to amount_shown on this entity hears it after the number is printed.

When the open function overrides a virtual method, the step list offers Call parent with the function’s name. The step runs the engine’s own version of that method. The virtual methods the engine lists have no body, so today the step does nothing for them.

The Dialogue message step shows a line of dialogue and waits for the player to answer. Its inputs are speaker, text and an optional prefab. It puts a DialogueBox on the stage, and removes it when the player answers.

  1. Add a Dialogue message step. In the Step panel, set its speaker to "Ann" and its text to "Hello".
  2. Click + at the foot of the step once for each choice, up to ten. − takes one away. The step gains a choice input and a flow output for each one.
  3. Add a Dialogue choice step for each choice and set its text. Wire its choice output to a choice input of the message.
  4. Wire each choice output of the message to the steps that run when the player picks it.

Check: run the project. The box shows the line and one button for each choice.

With no choices the box shows a Continue button, and the flow follows then. A choice with no wire is not shown. A choice whose visible input is false is not shown, and the other choices keep their own outputs. If no choice is shown, the flow follows then.

To use your own box, make a prefab whose root has a show_message method and a finished signal. Wire the prefab to the prefab input of the step, or set the graph_script/dialogue/prefab project setting to use it for every message.

  1. Click in the margin left of a step’s title. A red dot shows the breakpoint. Click again to take it off.
  2. Run the project. The debugger bar below the canvas says “No game is connected.” until the game attaches. Then it says that the game is running.
  3. When the game reaches the step it stops. The editor opens the function and selects the step. The bar says “Paused at” and the step’s title.
  4. Use Continue, Step into, Step over and Step out to move the game on. Pause stops a game that is running.

Check: the Stack lists each call that is waiting. Choose a level to see its Locals and Members. While the game is stopped, hold the pointer over a data wire to see the last value that crossed it.

The editor saves breakpoints in the project’s .orblit/editor folder, so they are there when you open the project again. They are not in the .ograph file, so a teammate does not get them.

  • The Step panel lists only the values a step already holds. A Set, Constant or Operator step added from the step list has no field for its name, value or operator. A Get dragged from Variables and an Emit dragged from Signals come with theirs.
  • A function that listens for a signal is a Signal received step. The engine runs one when the file holds it. The editor cannot add one yet.

A function that waits, such as a delay, hands its caller a GraphCall instead of a result. Connect to its completed signal to get the value when it ends. The class reference lists everything an entity can do.