Godot Version
4.3 stable
Question
(very new to Godot and programming in general, trying to graduate from Scratch 2.0 to something professional)
I’m trying to connect a signal with a variable to an instanced scene, and whenever the connect … command? line? (idk what it’s called) is executed, the game window crashes and it gives the following error:
Invalid access to property or key 'on_level_coordinate' on a base object of type 'Node2D'.
I’ve tried a lot of ways I’ve read to connect the signal using gdscript, since I know I can’t use the editor directly because the scene is being instanced after the game starts (so it doesn’t exist yet), but nothing has worked. As the error says, my scene “Pipe” IS a Node2D, but I don’t understand how or why that would be a problem.
Here’s my code for reference (being run in the base node of my tree, “Level”, also a Node2D):
extends Node2D
signal coordinate
var pipe_scene: PackedScene = load("res://Scenes/pipe.tscn")
func _on_player_dropped(coordinate_0: Vector2) -> void:
var Pipe = pipe_scene.instantiate()
$Pipes.add_child(Pipe)
connect("coordinate",Pipe._on_level_coordinate) #this makes it crash
emit_signal("coordinate",coordinate_0)
I’m also expecting this scene “Pipe” to be instanced multiple times, and for all of them to be connected to the signal “coordinate”. I hope this is enough context and I hope I used all of these words at least sort of correctly. Thanks in advance for any help anyone can give.