0 votes

Hello!
I was trying to make an endless runner type of game, but ran into difficulties using for loop to connect signals to the script. I tried manually connecting too, but it still throws the same error. Any help is appreciated.

Code:
Level code(Yes my endless runner game has levels):

extends Node2D

export (int)var speed = 200
var start = false

func spikes_action():
    print('dead')

func _ready():
    randomize()
    for spikes in $Map/Spikes.get_children():
        spikes.connect('spikes_action', self, 'dead')
    $Map/Goal.connect('goal_action', self, 'level_completed')

func _physics_process(delta):
    if Input.is_action_pressed("toggle_gravity"):
        start = true
    if start == true:
        for things in $Map.get_children():
            things.position.x -= speed*delta


func goal_action():
    print('Done!')

Spikes Code:

extends Area2D

signal dead



func _on_Area2D_body_entered(body:Node):
    if body.is_in_group('Player'):
        body.queue_free()
        emit_signal('dead')

Goal Code:

extends Node2D

signal level_completed


func _on_Area2D_body_entered(body:Node):
    if body.is_in_group('Player'):
        emit_signal("level_completed")
Godot version 3.5 stable
in Engine by (76 points)

1 Answer

0 votes

You've mixed up the signal name ("dead") with the function name to call ("spikes_action") in the connect () call.

by (141 points)
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 Frequently asked questions and 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 [email protected] with your username.