Timer doesn't work
Asked Answered
K

3

0

Hey, guys,

I've been testing some Godot features, and I'm having trouble understanding the Timer node. I attempted to send a signal to my player node, intending to print a debug message after 3 seconds, but the message never appears

[extends CharacterBody2D

var speed = 400

func process(delta):
var direction = Vector2(randi_range(-1,1), randi_range(-1,1))
random_move(direction )
$Timer.start()

func random_move(direction):
velocity = direction*speed
move_and_slide()

func _on_timer_timeout():
print("ok")
](https://)

Kimball answered 30/11, 2023 at 1:23 Comment(0)
S
1

Kimball $Timer.start()

Try changing that to:

if $Timer.is_stopped():
        $Timer.start()

Without that check, the Timer is being restarted every few milliseconds and will never time out.

Shahaptian answered 30/11, 2023 at 1:28 Comment(0)
S
0

Kimball Make sure that you actually connected timer's timeout signal to that signal handling function.

Sartor answered 30/11, 2023 at 1:27 Comment(0)
S
1

Kimball $Timer.start()

Try changing that to:

if $Timer.is_stopped():
        $Timer.start()

Without that check, the Timer is being restarted every few milliseconds and will never time out.

Shahaptian answered 30/11, 2023 at 1:28 Comment(0)
K
0

Shahaptian

Thanks! It's working now.

Kimball answered 30/11, 2023 at 1:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.