Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CoryParsnipson |
Hi, I was trying to create a timer and connect it to my gdscript completely programmatically. I followed some examples online but for some reason, the connection wouldn’t work. If I create a timer in the GUI and then use the inspector to hook up the signal, everything works fine. I would like to find out how to do it in the script, though. Is this a bug or something that is just not possible to do through scripting?
Example gdscript code that does not work:
var timer
func _ready():
timer = Timer.new()
timer.set_wait_time(2)
timer.connect("timeout", self, "_on_timer_timeout")
if self.is_connected("timeout", timer, "_on_timer_timeout"):
print ("YES")
else:
print ("NO")
func _process(delta):
if (Input.is_action_pressed("ui_up")):
timer.start()
func _on_timer_timeout():
print ("TIMEOUT")
============
In the console, it prints out “NO” to indicate that the connection was apparently not successful? And if I press the up arrow exactly once, nothing happens.