Random beginner-question: set a math-result as wait_time

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pferft

Hi everyone,

within a TimerNode I just managed to set up some calculations considering the current time and a user-entered time and it prints the right numbers:

var result_for_wait_time

func _on_that_button_pressed():

# ...getting some numbers and do calculations...

		result_for_wait_time = entered_time_in_secs - current_time_in_secs
		print (result_for_wait_time)

So this works. Now I want the result to be put into the following

func _ready():
	
	set_wait_time(result_for_wait_time)

so my parent LabelNode displays some countdown. This is all set up and working fine with a number entered directly, like for example set_wait_time(100), but replacing the 100 with result_for_wait_time throws me the error

Invalid type in function 'set_wait_time' in base 'Timer (TimerScript.gd)'. Cannot convert argument 1 from Nil to float.

I have the feeling that I’m missing some rather simple little thing… how can I get my calculation results in there?

:bust_in_silhouette: Reply From: timothybrentwood

Cannot convert argument 1 from Nil to float. means that at the time you are calling set_wait_time() the value for result_for_wait_time has not been set. You likely want to change:

func _on_that_button_pressed():

# ...getting some numbers and do calculations...

    result_for_wait_time = entered_time_in_secs - current_time_in_secs
    start(result_for_wait_time)
    # or set_wait_time(result_for_wait_time) and call start() later

and remove set_wait_time(result_for_wait_time) from _ready()

That’s it, perfect, thanks!
I would never have thought of that “start”…

pferft | 2021-05-20 15:33