I created a script, blink .gd, without a scene, the essence of which is to teleport an object to the mouse
player.gd
onready var _blink = preload("res://src/characters/skills/blink/blink.gd").new()
...
func blink():
_blink.skill(self)
blink.gd
var _timer : Timer = null
var _cooldown : bool = false
func _init():
_timer = Timer.new()
_timer.set_timer_process_mode(0)
_timer.set_wait_time(1)
_timer.set_one_shot(true)
add_child(_timer)
_timer.connect("timeout", self, "_reload")
func skill(_target: KinematicBody2D) -> void:
...
if !(_cooldown):
_timer.start()
_cooldown = true
else:
return
...
func _reload():
_cooldown = false
and it doesn't work. I checked timer.isconnected and it returns true.
I did something similar in scripts attached to scenes and the timer worked.
UPD
I added to player.gd code addchild(blink), and timer work, but the script no longer teleported the player.
Sorry for any mistakes, English is not my native language.