Hello :)

So, I'm new to Godot, been testing it out for a few days and watching Youtube..

I'm having trouble with Timer, it absolutely won't start. However, it will start if I set autostart = true, but I'd like to start it manually. What am I doing wrong?

extends Node

onready var mySprite : Sprite
onready var myTimer  : Timer

func _ready():
	mySprite = Sprite.new()
	mySprite.texture = preload("res://icon.png")
	mySprite.global_position = Vector2(300,300)
	self.add_child(mySprite)
	
	myTimer = Timer.new()
	myTimer.wait_time = 2
	#myTimer.autostart = true
	myTimer.start()
	#myTimer.start(2)
	self.add_child(myTimer)
	
	myTimer.connect("timeout", self, "_on_Timer_timeout")
	
func _on_Timer_timeout():
	print("Timer timed out")
	if mySprite.visible:
		mySprite.visible = false
	else:
		mySprite.visible = true

thanks!

You can't start a timer if it's not in the scene. So first call add_child() and then start()

@xyz said: You can't start a timer if it's not in the scene. So first call add_child() and then start()

omg, so simple... thank you! :)

a year later