Godot Version
v4.2.2.stable.official [15073afe3]
Question
I have created two timers using Timer.new() on assignment to their variables. Whether I use mytimer.one_shot = true in _init, in _ready or using a signal that calls a function that sets one_shot to true, it does not work. I have to do it even after that.
Is this a bug? Why does it not work? According to the documentation, ready is emitted after _ready called and done. Using start(seconds) doesn’t do anything to one_shot as I can see in the source code.
have you added child the var new_timer= Timer.new()
?
I did that in the _ready function of my node
curryninja:
did that
you mean add_child(new_timer)
? then new_timer.start()?
Also did you know you can just
await get_tree().create_timer(5).timeout
for one_shot?
Here are the code snippets.
var chain_timer = Timer.new()
var action_timer = Timer.new()
func _init():
action_timer.timeout.connect(_on_action_timer_timeout, CONNECT_DEFERRED)
chain_timer.timeout.connect(_on_chain_timer_timeout, CONNECT_DEFERRED)
func _ready():
add_child(action_timer)
add_child(chain_timer)
action_timer.one_shot = true
chain_timer.one_shot = true
func someFunc():
action_timer.start(current_action.execution_time)
try just do it like this
var chain_timer:Timer
var action_timer:Timer
func _ready():
action_timer=Timer.new()
chain_timer=Timer.new()
add_child(action_timer)
add_child(chain_timer)
action_timer.timeout.connect(_on_action_timer_timeout, CONNECT_DEFERRED)
chain_timer.timeout.connect(_on_chain_timer_timeout, CONNECT_DEFERRED)
action_timer.one_shot = true
chain_timer.one_shot = true
func someFunc():
action_timer.start(current_action.execution_time)
That works!
I do wonder why though. Maybe it creates a new object after the ready function…
system
Closed
August 25, 2024, 4:49pm
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.