Timer().timeout signal not working

Godot Version: 4.2.1 Stable Mono

Question:

My first mistake was using GDscript instead of C# to write this game.
I am used to C++ mainly since most of my experience is with unreal but
the way variable scope works in GDscript is insanely obtuse and unintuitive
to someone who is used to just typing “import” or “#inlcude” to be able to access things.

I have multiple Timer() functions in my game. All in their own function.
All but one of them work as expected but one of them simply WILL NOT trigger
the timeout signal which is then supposed to call a function on timeout.
I have spent hours using print statements to determine that the Timer is being started and is reaching 0 but for some reason, isn’t sending the signal. Normally this wouldn’t matter since I could just do “if timer.time_left == 0: timeout_function()” but this particular timer is started every time an instance of a certain class is created and I need to keep track of 1 timer per class instance. Also tried using “await” which also didn’t work because the timeout signal isn’t being sent. I’ll provide the timer function here (variable names have been changed.)

func timer_start(new_object):
print("Clock is ticking for " + new_object.object_name)
var mytimer = Timer.new()
mytimer.one_shot = false
mytimer.paused = false
mytimer.timeout.connect(_tf_timer_runout)
timer.start(2)

I have pretty much given up using the Timer() function for this since it’s not really designed for having multiple instances apparently. My new strategy has been to add a countdown variable to my class and -=1 from it every time _process() runs. Assuming I want the countdown to last 3 seconds, I set the countdown to 180 since my game runs at 60 fps. BUT this also does not work because you can’t make public variables in GDscript. It’s not possible. Everywhere I look tells me to use this autoload thing in project settings which is useless in my case since that will only give me variables of the class itself. Not a class instance. can’t use @export because its “not allowed at this level” .

Basically, I want to be able to access a variable in another function from inside the _process() function in the same script attached to the root node.

Really have no idea what to do. I’m about to re write the whole project in C# at this point.

Timer is a node, so maybe it didn’t work because you forgot to add it to the scene tree?

And if you want to make your own timer in _process(), you can do it with the get_ticks_msec() function.

3 Likes

I’m about to re write the whole project in C# at this point

when i first looked at godot my first instinct was to rag on gdscript. but there are many who write amazing games in gdscript. like any language, it just takes time. for me c# is best and it might be best for you. as far as i know, you can migrate to c# one gdscript at a time. the only thing i am unclear is I don’t think godot/c# works for web.

1 Like

I never figured out the timer situation but I did find a work around as crude as it may be. I keep all of these instances and their properties in a nested array for easy access
so this basically loops over every inner list and sets the parameters accordingly.

func _process(delta):
for i in nested_array:
i[7] -= 1
if i[7] <=0:
i[7] = 120
i[5] += 1
if i[4] >= 5: print(“You’re winner”)