How can i connect signal to another node ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cah9xddd

Making first platformer and wanna add my picked up coin signal from coin scene to another scene(lvl1).But i dont wanna make 150 signals inside lvl1 script , just wanna add 1 signal from coin scene to lvl1 scene but i dont know how to do this.Thanks for helping

:bust_in_silhouette: Reply From: Wakatta

First get a reference to that node which depends on how your nodes are added to the Scenetree

Coin Node.gd

extends Node

signal picked_up

func _enter_tree():
    var lvl1_scene = get_node("path/to/lvl1 scene")
    connect("picked_up", lvl1_scene, "_on_coin_pickup", self)

lvl1_scene.gd

func _on_coin_pickup(coin):
    print(coin.name) #do something with coin

The example above does not emit the signal which you’ll probably want to do on some condition met