Replies: 2 comments 2 replies
-
If an inner class were flagged as
Or would this be a global alias that is uniquely within the scope of the GDScript language? +1 for also including static functions in this. I could also foresee eventually adding extension methods to GDScript using this in tandem with an With all that said, I think it would be confusing and/or weird for inner classes to be something that could be recognized as a global script class by the engine, so I wouldn't do that. And I do like the idea of enums, constants, and static methods being things that can be globalized within GDScript, BUT rather than doing it on a case-by-case basis, I think it would be better to have a |
Beta Was this translation helpful? Give feedback.
-
This will not be true in the future as we want to add static variables (#6156). In this regard, it is worth rethinking this idea. Global functions and variables are a double-edged sword, but we will probably add this feature someday (the only question is how). |
Beta Was this translation helpful? Give feedback.
-
Add the ability to give inner classes and enums global names (as aliases to local names).
For example, you can use
ItemID.SWORD
instead ofItemDB.ID.SWORD
andItemInfo
instead ofItemDB.Info
.Alternatives:
1.1. Don't use inner classes. I almost always do this, but for "structs" inner classes are fine. This part is just for completeness.
1.2. Don't use named enums (then it will be
ItemDB.SWORD
). However, you won't be able to use an enum as a type.2. Add a
using
analog that allows you to import a class/enum into a script with a short name (also namespaces are planned in future versions as far as I know).use ItemDB.ID as ItemID
or something similar. However, this will require repeating this line in every script that uses this class/enum.In 3.x you can use
const MyEnum = OtherClass.MyEnum
. In 4.0 this doesn't work properly, but I'm not sure if it should.I only suggest inner classes and enums as they are used as types (plus reducing the number of enum components from 3 to 2 in places of use). However,
@global
can also be used with static functions and constants, as they are stateless. This would allow, for example, to remove theUtil.
prefix:Beta Was this translation helpful? Give feedback.
All reactions