What data type is an event? (Q: Connect to events)

Godot Version

4.3rc3

Question

i think i want to know the data type for an event?

My goal: My tutorial is 24 steps - wait for button press, wait for item built, wait for person to die, etc. i think i want to use a state machine with one class per state. Each class waits for one or more events. i want to generically pass in the events to wait for (if that’s possible).

@export var wait_for: signal [doesn't work]
func enter():
    wait_for.connect(on_wait_finished)
func on_wait_finished():
    emit_signal("finished")

My approach is possibly quite stupid but i’m not sure how else to handle this in a general purpose way.

Example Tutorial:

  1. Wait for “press start button” (start_button::pressed)
  2. Wait for “wave ended” (Level::wave_ended)
  3. Wait for “select a tower” (red_tower::pressed)
  4. Wait for “place tower” (Level::tower_built)

signal is a keyword, Signal is the type. Though I don’t think exporting it will be of much use to you.

@export var wait_for: Signal # valid

You could use the 3.x string based signal/connection format as you are emitting. Though I understand it’s error prone to type out a signal name. You will also need to supply the object connecting from.

@export var wait_for: String
@export var connect_from: Node
func _ready() -> void:
    connect_from.connect(wait_for, on_wait_finished)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.