Martian Mike - The For Loop - "Invalid get index 'touched_player'" error

Hi folks, I tried to replicate word for word and step by step a mini game based on Martian Mike however I’m getting an error when running the game. Error is Invalid get index ‘touched_player’ (on base: ‘AnimationPlayer’).

Code for Level that I’ve got:

@onready var start_position = $StartPosition
@onready var player = $Player

func _ready():
	var traps = get_tree().get_nodes_in_group("traps")
	for trap in traps:

func _process(delta):
	if Input.is_action_just_pressed("quit"):
	elif Input.is_action_just_pressed("reset"):

func _on_deathzone_body_entered(body):

func _on_trap_touched_player():
func reset_player():
	player.velocity = Vector2.ZERO
	player.global_position = start_position.global_position

Code for

extends Node2D
signal touched_player

func _on_area_2d_body_entered(body):
	if body is Player:

Really stumped! :frowning: Here’s another screenshot in detail when that error message appears when I run the game:

Hi there,

Just wondering what is all inside the traps node group in the scene?

at first glance, it sounds like, its going through all the nodes you have added under “traps” in the scene, and one of them doesnt have the “touched_player” signal to connect to.

I just checked the nodes in the Traps group of nodes and they’re all identical to the Martian Mike one. I also checked the node signals for each object on both projects, all the same, nothing connected as the lesson advises to remove all of that due to the for loop lesson.

I’m happy to provide additional screenshots where you may suggest. :slight_smile:

FIGURED IT OUT! Yes I just had another look! I accidentally tagged an Animation Player node with the “traps” group. Removed it, solved. That wow… Once again :man_facepalming:t2:

Thank you for your help :slight_smile:

Edit: here’s the screenshot of what I had. Went in to Manage Groups and found the animation player was in there too by accident. Removed, solved.

1 Like

Nice one. Glad it’s working :slight_smile:

Thank you again, this is such great help! :smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms