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. Make the graph script
Section titled “1. Make the graph script”- Open the Graph tab at the top of the editor.
- Open the File menu on the tab and choose New….
- Set Name to
counter. Leave Extends onEntityand Folder onres://. Choose Create.
Check: counter.ograph opens in a tab above the canvas. The Extends class
is the base type of the script.
2. Attach it to an entity
Section titled “2. Attach it to an entity”- Open the 3D tab and select an entity in the Scene panel.
- In the Inspector, choose Attach a script.
- Choose Graph, pick
counter.ographand choose Attach. - Save the scene with Cmd+S.
Check: the Script row in the Inspector names counter.ograph.
3. Add a variable and the start function
Section titled “3. Add a variable and the start function”- Go back to the Graph tab. In Variables, choose +.
- Set Name to
amount, Type to int and Default to3. Turn on Show in the Inspector, then choose Add. - In Functions, open the Override a virtual list and choose
_start. The engine calls_startonce, when the entity starts.
Check: _start opens on the canvas with an Entry step.
4. Print the variable
Section titled “4. Print the variable”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.
- Select the Entry step. Press Space, type
printand press Shift+Enter. - Drag the
amountrow from Variables onto the canvas. This adds a Get step for that variable. - Drag from the Get step’s
valuepin to the Print step’stextpin.
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.
5. Run it
Section titled “5. Run it”- Save the graph with Cmd+S.
- 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.
6. Send a signal
Section titled “6. Send a signal”- In Signals, choose +. Rename the new row to
amount_shown. - Drag the row onto the canvas. This adds an Emit step with its
signalset to"amount_shown". - Drag from the Print step’s
thento the Emit step’srun.
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.
Call the engine’s version
Section titled “Call the engine’s version”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.
Show a line of dialogue
Section titled “Show a line of dialogue”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.
- Add a Dialogue message step. In the Step panel, set its
speakerto"Ann"and itstextto"Hello". - Click + at the foot of the step once for each choice, up to ten.
− takes one away. The step gains a
choiceinput and a flow output for each one. - Add a Dialogue choice step for each choice and set its
text. Wire itschoiceoutput to achoiceinput of the message. - 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.
Stop on a step
Section titled “Stop on a step”- Click in the margin left of a step’s title. A red dot shows the breakpoint. Click again to take it off.
- 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.
- 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.
- 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.
What is not built yet
Section titled “What is not built yet”- 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.
