Follow

In , I got two variables in a file, both holding instances of one internal class. The script is not attached to a node and I cannot access these variables. Coming from , I thought this would work if I could preload the script.

Do I need to attach the script to a node in order to access the class instances? I'm not sure how databases are handled here

@SteelWool
In GDScript, a script file is basically a definition of a class. Any variables inside are members of that class. You can access them through instance of that class, but they are not "shared" between many instances. If you want to have some "data store" functionality, there are several options. My favorite is using custom resources as data containers.

@limbo @SteelWool To add on to this, I think you can maybe achieve what you're trying to do by making the variables static. So "static var foo = ...", then I think preload("script.gd").foo should work?

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!