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.