Replies: 1 comment 6 replies
-
Since one script represents one class, it's easy to determine the type of a node when a script is attached. What happens when you attach a multi class script to a node? How will it know which class's functionality to assign to the node? |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Add support for multiple individual named classes in the same script file (Gdscript)
Description
Add support to have multiple independent named classes in the same file. I.A Defining two classes within the same file, then being able to reference those classes completely independently as if they were defined in two different files.
Describe the project you are working on
I am working on a map painting game with heavily abstracted logic for events, popups, buildings and alike (for future mod support). I propose this feature as it would be really helpful for me when I write different implementations of some type of resource. For example, I have a "condition" class that is used to validate different types of conditions within the game, which has different subclasses for different implementations of the conditions class (an AND condition, a resource check condition etc.)
Describe the problem or limitation you are having in your project
Sometimes you have really small classes, or a collection of implementations that are different enough to warrant being different classes, but similar enough that it would be more readable to have them all in one file. It's also quite annoying to navigate a project that necessitates having so many files (even with a neat folder structure).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add syntax for defining different classes within the same file. A way to do this would be to define multiple "
extends X class_name Y
" below eachother to signify different classes.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
(This obviously depends on how the team wants to implement the feature)
Then in another file
If this enhancement will not be used often, can it be worked around with a few lines of script?
Personally, I think it is used often. But if it isn't you can create a superclass in the file, and then add a bunch of subclasses within that superclass, this isn't nice however, since you would have to refer to that superclass when you want to create instances of the subclasses and that should be unnecessary.
Is there a reason why this should be core and not an add-on in the asset library?
It adds fundamental syntax to the gdscript language, so I think it fits as a core feature.
Beta Was this translation helpful? Give feedback.
All reactions