–1 vote

I'm trying to implement a system where when the player's health variable decreases because of a collision with an enemy, a connection is made to the level which is auto-loaded to link to the function in the level script. The error message is:

Invalid set index 'Player' (on base: 'Node2D (Level1.gd)') with value of type 'KinematicBody2D (Level1Player.gd)'.

Player scene _ready() func:

func _ready():
timer.connect("timeout",self, "_on_DeathTimerPlayer_timeout")
Level1.Player = selfconnect("_on_EnemyDetector_body_entered", Level1.Player, "on_health_updated")

The palyer's damage function:

func _on_EnemyDetector_body_entered(body: PhysicsBody2D):
    print(body.name)
    if not body == self and not body == RigidBody2D:
        health = health -1

Level variables:

var health = 6
var Player: KinematicBody2D

The function to change the animation for each value of health:

func on_health_updated():
    health = health -1
    if health == 6:
        $Background/AnimationPlayer.play("GameHeart1Full")
        $Background/AnimationPlayer.play("GameHeart2Full")
        $Background/AnimationPlayer.play("GameHeart3Full")
    elif health == 5:
        $Background/AnimationPlayer.play("GameHeart1Full")
        $Background/AnimationPlayer.play("GameHeart2Full")
        $Background/AnimationPlayer.play("GameHeart3Damage1")

(... and so on)

Does anyone have any clue what the problem is here?

Godot version 3.2.3
in Engine by (47 points)

You cannot assign this to a variable

Level1.Player = selfconnect("_on_EnemyDetector_body_entered", Level1.Player, "on_health_updated")

also, it is self.connect

Please log in or register to answer this question.

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.