Reference a script file that holds constant values

Godot Version

Godot-4 on windows

Question

I created a GDscript file called miracle_database that consists of 3 data dictionaries, and several functions that retrieve records from these dictionaries. I tested all the functions in the debugger and they work well.

What I’m wanting to do now is create a “character” class that can access the functions in that file when instantiating a new character object. I set it up but I can’t understand how to access that file. If needed I can share the code tomorrow as I’m writing this from my phone.

Yes I’m somewhat new to Godot. I have ADHD and struggle to figure things out and Copilot couldn’t help me…

You can make your miracle_database script a global script. You can imagine it like an node with your script that is constantly active no matter what scene you are currently playing (coexistant).
If you want to do so you can go to your project settings and assign your script there as a global script.

You can access it from any script like so:

var my_data = MyGlobalScript.get_data_method()
1 Like

Great! I saw the auto loads section in there and tried to use it. Didn’t work as I expected at first but then I realized it gave it a variable name of Miracle database and so that’s how to access it.

Thanks so much!