0 votes

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?

Godot version 3.3
in Engine by (331 points)

1 Answer

0 votes
Best answer

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()

by (2,520 points)
selected by

That's it, perfect, thanks!
I would never have thought of that "start"...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.