+1 vote

When I made a variable in a script, I made it an autoload & tried to access its contents from a different script and got this error:

Invalid get index 'game_data' (on base: 'GDScript').

Here is my autoload save script.
&& here's my functions that all get the same error (different variable name)

Godot version 3.4.4
in Engine by (30 points)

1 Answer

0 votes

When you set up the AutoLoad classes, you give them a name that you'll use to refer to them. So you just need to prefix game_data with whatever name you assigned it in the AutoLoad settings.

Here's a screenshot where I create one called Globals and one called EffectsPlayer and in my code, to use something from Globals for instance, I would call Globals.color = "blue"


by (96 points)

Okay that makes sense. I did add the Save Singleton to autoload. The script is called "save.gd" && the singleton is called "Save" In my variable, which you saw, is a dictionary & I'm trying to get the dictionary value from game_data which ended up like this Save.game_data.fullscreen or something similar. I'm just confused on why it is giving me the error to begin with. I've even tried getting the dictionary value like this Save.game_data["fullscreen"] && it gave me the same error.

You get the same error about game_data not existing or fullscreen?

Oddly enough, it's working properly now. I didn't really change anything either. that's strange but I'll comment here if it acts up again like that. Thanks for the help! Much appreciated!

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.