0 votes

I have this scene structure:

-Main
--Dungeon

Then I instance another Node with this code:

onready var PLANTAGE = preload("res://Waffen/Plantage.tscn")
var new_Plantage1 = PLANTAGE.instance()
get_node("/root/Main").add_child(new_Plantage1)

How can I connect a signal from Dungeon with the instanced Node?

in Engine by (334 points)

1 Answer

0 votes
Best answer

You don't mention which node the script is attached to. Nor the name of the signal. So I'll assume the script is attached to your Dungeon-node and you want to connect the signal "fire" it's emitting to a function called "burn" in your Plantage-scene:

connect("fire", new_Plantage1, "burn")

Also take a look at this!

by (10,331 points)
selected by

I tried it on another thing and it dont works. This is what I wrote in the Dungeon Script:

onready var CONTAINER = preload("res://Scenen/Container.tscn")

var new_Container = CONTAINER.instance()
get_node("/root/Main").add_child(new_Container)
connect_to_Container(new_Container)

signal Stop

func connect_to_Container(container_node):
    container_node.connect("Stop",container_node,"delete")

And this on the Conatiner Node:

func delete():
    print("It works")

But it dont print anything. What is my mistacke?

It has to be

self.connect("Stop", container_node, "delete")

not

container_node.connect("Stop", container_node, "delete")

The former connects the "Stop"-signal of the Dungeon-script with the delete-function of the Container-script. The latter connects the "Stop"-signal of the Container-script with the delete-function of the Container-script.

Thanks, now it works!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.