Godot Version
Godot 4
Question
Hi, I’m creating a platform game with coins and doors to change levels. In the code there’s a problem.
This is the code for the levels 1 and 2 (shared)
extends Node2D
@export var tutorial_num = 0
func _ready():
print("Tutorial " + str(tutorial_num))
for monete in $Moneta.get_children():
monete.monete_collezionate.connect(_on_monete_collezionate)
func _on_door_player_entered(tutorial):
get_tree().change_scene_to_file(tutorial)
func _on_monete_collezionate():
$CanvasLayer/Monete_collezionate.text = "Monete collezionate: " + str(Globale.gemme_collezionate)
And this is the code of the coins
extends Area2D
signal monete_collezionate
func _on_body_entered(body):
if body.name == "Player":
print_debug("Collected")
Globale.gemme_collezionate += 1
monete_collezionate.emit()
queue_free()
It gives me the error:
Invalid get index ‘monete_collezionate’ (on base: ‘CollisionShape2D’).
Can you please give me the reason?