0 votes

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 onLineEdittextchanged(new_text) function,I wrote the following code:

WorldData.Seed = new_text
print(WorldData.Seed)

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

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

in Engine by (45 points)

Are you sure WorldData.gd 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.

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.

Thanks...I've fix the problem...
The error is because I have two files with the same name World data.gd,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....

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.

Please log in or register to answer this question.

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.