Help needed for my dialogue system (using signals)

Godot Version : 4.3 stable

Hello, I’m quite new to Godot and I’m currently trying to work on an important project for my studies (the deadline is also only 2 months, so I’m really trying my best to make a somewhat functional game before that). I’m trying to get a dialogue system to work, and I’d like to make it so that the player cannot move while talking (or interacting with something). I made a script for interactable objects, and here is the code I’m using now :

class_name Interactable extends Node2D

@export var on_interact: Array
var can_talk = false
signal started_talking
signal finished_talking

var dialogue_index = -1


func _process(delta: float) -> void:
	if Input.is_action_just_pressed("interact") and can_talk:
		dialogue_index += 1
		if dialogue_index >= len(on_interact):
			finished_talking.emit()
			dialogue_index = -1
		elif dialogue_index >= 0:
			started_talking.emit()
			print(on_interact[dialogue_index])


func _on_collision_body_entered(body: Node2D) -> void:
	can_talk = true


func _on_collision_body_exited(body: Node2D) -> void:
	can_talk = false

My question would be : how do I connect these signals (started_talking and finished_talking) to the player script so that I can disable control while the dialogue is on screen ? (Btw, I haven’t made the actual dialogue box appear when talking yet, but I’ll be working on it as soon as I fix that issue first)

Declare your signals in an autoload instead of the script they’re in now. Then emit like this <name of your autload script>.<name of your signal>.emit().

You can connect a function in your player script like this: <name of your autoload script>.<name of your signal>.connect(<name of function in player you would like to call>.bind())

1 Like

Thanks for the help ! Everything works now.