K

Im not sure what is wrong

Preston Bruce(KingCarnival)

I am working on the lights practice and am failing the second step. Im not sure what is wrong with my code:


extends Area2D

onready var timer := $Timer
onready var light := $Light
onready var animation_player := $AnimationPlayer

func _ready() -> void:
timer.connect("timeout", self, "_on_Timer_timeout")
# Connect the body_entered signal to the _on_body_entered() function
connect("body_entered",self,"_on_body_entered()")



func _on_body_entered(body: Node) -> void:
animation_player.play("turn_on")
# Set light.enabled to true to turn on the lights and start the timer
# to turn off the lights after it counts down.
timer.start()
light.enabled = true



func _on_Timer_timeout() -> void:
animation_player.play("turn_off")
light.enabled = false
  • Nathan Lovato replied

    You're almost there! The reason you're not passing and Godot cannot turn on the lights is a little typo in your connection of body_entered.

    connect("body_entered",self,"_on_body_entered()")

    You wrote _on_body_entered() with parentheses inside the second string. The engine expects the name of the function, without parentheses (parentheses are a tool to execute a function).

    You can change the code like this to pass the practice:

    connect("body_entered",self,"_on_body_entered")
    1 love
  • K
    Preston Bruce(KingCarnival) replied

    Thank I was pull my hair out trying to figure it out