#Struggling with connecting with signals via code.

3 messages · Page 1 of 1 (latest)

rain zephyr
#

Hey,

I have a script that emits a signal "DialogueFinished". I'm trying to connect to that signal in a different script like this:

    dialogueScriptReference = get_node("../Player/Dialogue")
    if(dialogueScriptReference):
      dialogueScriptReference.connect("DialogueFinished",self,"DialogueDone")
    else:
      print("dialogue is null")

from my understanding this should connect to the signal DialogueFinished and run the DialogueDone() function but im receiving this error instead:

Invalid type in function 'connect' in base 'Control (Dialogue.gd)'. Cannot convert argument 2 from Object to Callable.
last heart
#

Hello, there are two connect methods in Godot 4.
One is a function of the Node class, one is a function of the Signal class.

You are attempting to use the first one (Node class) which has the following arguments:
connect(signal: StringName, callable: Callable)

So your code would need to be:

dialogueScriptReference.connect("DialogueFinished", self.DialogueDone)

Here's the other method, the function belonging to Signal class:
signal_variable.connect(callable)

dialogueScriptReference.DialogueFinished.connect(self.DialogueDone)

Let me know if you still have issues! @rain zephyr

#

(Also self is not needed but helps for readability/clarity)