Skip to content

Calling Dialogue Functions

Dia:
    "You can call functions from written Dialogues.
    Provided that there's the Object
    to call said functions: the caller."
:
    "Let's use a simple ColorRect node as a caller."
:
    "And we'll modify its properties
    using its various setter functions."
  1. Add ColorRect node to the scene. Adjust its position and size to your liking.

    MyScene
      ├─ Stage
      ├─ PanelContainer
      │     └─ VBoxContainer
      │         ├─ Label
      │         └─ DialogueLabel
      └─ ColorRect
    

    And reference it in the script.

    @onready var color_rect = $ColorRect
    
  2. Register it as a caller in the Stage, using add_caller().

    extends Control
    
    var dlg : Dialogue # Load/create Dialogue here
    
    @export var stage : Stage
    @onready var color_rect = $ColorRect
    
    func _input(event):
        if event.is_action_pressed("ui_accept"):
            stage.progress()
    
    func _ready():
        stage.add_caller("ColorRect", color_rect)
        stage.start(dlg)
    
    add_caller() requires 2 arguments:

    • The ID/name of the caller object to be used in the written Dialogue.
    • The object itself.
  3. We are ready to call functions on our ColorRect. We'll append to the Dialogue above.

    :
        "Now, I will turn this rectangle blue..."
    :
        "Ta-da~!"
    
        ColorRect.set_color("#0000FF")
    

Code Summary

MyScene
  ├─ Stage
  ├─ PanelContainer
  │     └─ VBoxContainer
  │         ├─ Label
  │         └─ DialogueLabel
  └─ ColorRect
extends Control

var dlg : Dialogue # Load/create Dialogue here

@export var stage : Stage
@onready var color_rect = $ColorRect

func _input(event):
    if event.is_action_pressed("ui_accept"):
        stage.progress()

func _ready():
    stage.add_caller("ColorRect", color_rect)
    stage.start(dlg)