Invalid set index error while setting singleton(autoload) variable/properties

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

I created a singleton(autoload) in godot and created a variable called Seed with the following syntax:

var Seed

In my LineEdit node,I send a signal to itself when the text in the line edit mode has changed.

In my _on_LineEdit_text_changed(new_text) function,I wrote the following code:

WorldData.Seed = new_text

Unfortunately,I received an error during test run,which says:
Invalid set index ‘Seed’(on base:‘Node (’) with value of type ‘String’.

I’ve tried converting the data types of various variables involved,but till now the error still persist…

Are you sure contains the line var Seed? Have you saved? Because this is exactly the error you’d get when you try to write to a variable of the singleton that isn’t defined in the script. I tried to reproduce your problem and couldn’t.

njamster | 2020-02-25 16:15

Hah - yep, was about to suggest the same thing. What you wrote above should (and does) work. I can only assume the Seed variable really isn’t in the World script, you haven’t saved the script yet, or you have some other compilation error getting in your way.

jgodfrey | 2020-02-25 16:25

Thanks…I’ve fix the problem…
The error is because I have two files with the same name World,so I’ve chose the wrong one to use as singleton(autoload),which is the one without the seed variable…
Thanks again for helping me to find the error…

God Of Theory | 2020-02-26 09:45

I get a very similar error, only says “Invalid get index”. Variable is present (has been for months), autoload is saved (had been for months) and it only happens in the editor, when I open the affected script, never at runtime.

Even then it’s random (sometimes it throws the error, sometimes it does not, for the same script, when I repeatedly open and close them. Feels like an editor issue to me.

attila | 2020-06-26 12:20