-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add static/class variables #5025
Comments
This was already discussed in godotengine/godot#6840 a while ago and rejected. |
consider using |
In fact, the ProjectSettings singleton was even called Globals in the Godot 2.x days 🙂 |
I've read the discussion and it seems the main problem is
Why will it be super confusing tho? |
|
Does it work for Godot 4 as well? |
was just about to say; no in 4 const Dictionary will be fully constant |
godotengine/godot#6840 (comment):
|
By using a singleton in combination with a var Dictionary "statics" are still possible. |
If you have a singleton, every property is effectively "static". |
I wanted to create a Singletone that is only instanced in a Scene, instead of populating Project Settings with an Autoload. The reason for that is that this is a Singletone that only makes sense during Gameplay (in my particular case, it generates "damage toasts" in a 3D scene), so what I had in mind was:
Not using a Singletone means I'll have to pass the reference for this node around, which is cumbersome and boring. Creating an Autoload for this object is okay, but I'd much prefer having the instantiation behavior contained in my script instead of relying on Autoload, so anyone knows what to expect of the script without having to check whether this is checked on Autoload, if it's doing something during the game initialization, etc. This is kind of a middle-ground between between being quick to develop and be sufficiently scalable, and not having |
Then again, I can just create a "Singletones.gd" autoload with typed variables for each singletone I want, and populate them on-the-fly. It's not like there isn't a lot of ways to circumvent this, but developers expect |
consider having a class for all game entities that can take damage, e.g. |
Superseded by #6156. |
Describe the project you are working on
Games, plugins
Describe the problem or limitation you are having in your project
I have some classes with some common data than may be changed during a game, and I don't need to create an object for it.
In Python I can just
that would print 2.
In GDScript I can't do this.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Adding static/class variables would solve the problem, you don't need to create an object to use these variables.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
would print
2
another example:
script1.gd:
script2.gd:
would print
2
If this enhancement will not be used often, can it be worked around with a few lines of script?
It can't, this is a gdscript feature
Is there a reason why this should be core and not an add-on in the asset library?
It can't, this is a gdscript feature
The text was updated successfully, but these errors were encountered: