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?