0 votes

I am getting this error: Invalid set index 'set_wait_time' (on base: 'null instance') with value of type 'float'. when start() is called.

duration and frequency are timers and child nodes.

const AMPLITUDE = 20
const DURATION = 0.2
const FREQUENCY = 15

func start():
    $duration.set_wait_time = DURATION
    $frequency.set_wait_time = 1/float(FREQUENCY)

I am new so I'd greatly appreciate if you could help :D

Godot version 3.2.3 stable
in Engine by (15 points)

1 Answer

0 votes
Best answer

And where start() is called, do you check if all nodes are ready?

 $duration.set_wait_time = DURATION
 $frequency.set_wait_time = 1/float(FREQUENCY)

One of your nodes is not ready (null instance) then this part is executed. So you assign float to something what not yet exist.

by (892 points)
selected by

Like this or not? I tried this and it did not work.

func turn():
    var screenShake = preload("res://levels/screenShake.gd").new()


onready var duration = get_node("duration")
onready var frequency = get_node("frequency")

func start():
    duration.set_wait_time = DURATION
    frequency.set_wait_time = 1/float(FREQUENCY)

Sorry if I am being stupid.

What is screenShake.gd?
Is it named class: https://docs.godotengine.org/en/stable/getting_started/step_by_step/scripting_continued.html#register-scripts-as-classes , or it extends some other class with extends keyword but does not have a name( no class_name keyword used)?

Oh, I think I did use GDScipt instead of PackedScene.

I've fixed it now.

Thanks a lot!

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 Frequently asked questions and 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 [email protected] with your username.