Error - Invalid set index 'set_wait_time' (on base: 'null instance') with value of type 'float'.

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

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)
    $duration.start()
    $frequency.start()

I am new so I’d greatly appreciate if you could help :smiley:

:bust_in_silhouette: Reply From: yrtv

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.

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

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

.

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.

berez | 2021-02-08 08:59

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

yrtv | 2021-02-08 13:10

Is it possible you made the same mistake? (Used GDScript instead of PackedScene)
Nonexistent function '...' in base '...' - Archive - Godot Forum

GDScript
GDScript — Godot Engine (stable) documentation in English

PackedScene
PackedScene — Godot Engine (stable) documentation in English

yrtv | 2021-02-08 16:05

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

I’ve fixed it now.

Thanks a lot!

berez | 2021-02-08 17:47