Skip to content
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

Implement mustoverride/abstract class members in GDScript #6973

Open
me2beats opened this issue May 29, 2023 · 2 comments
Open

Implement mustoverride/abstract class members in GDScript #6973

me2beats opened this issue May 29, 2023 · 2 comments

Comments

@me2beats
Copy link

me2beats commented May 29, 2023

Describe the project you are working on

I'm creating a plugin like the Command Palette.
Its main idea is to allow users to create their own commands easily.
Each command (I call it an action) is a gdscript file or gdscript class which extends Action class.
It has func run() that should be overridden by the user. This function is called when the command is executed.
Also it has fields (properties) like id (uuid string), info (Dictionary with the command name, author, version and description) and these properties should also be "overridden"/set by the user.

Describe the problem or limitation you are having in your project

Idk how implement it better than having must-override methods and properties, so I would really like to have this feature in GDScript.
It also could help us, developers, not allowing making mistakes like forgotten overrides

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Must-override methods proposal already exists
#1631
so this one is for must-override properties

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This can use mustoverride annotation, the name can be more intuitive tho.
it can be named abstract as well

class A:
    @abstract var x:int

class B:
    extends A
    var x = 1 # **

If you don't set x explicitly in B, the error will be raised like "x should be overridden"

** as you can see it requires new feature — ability to override parent class properties default values
#338

Also note that Godot 4.1 introduces static vars. And they should (logically) be mustoverridable as well.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. At least currently there is no a way to manually (using a plugin for example) check if the script has a property in the parent class that should be overridden but doesn't, and raise the editor error

Is there a reason why this should be core and not an add-on in the asset library?

This is a GDScript feature

@JoNax97
Copy link

JoNax97 commented May 29, 2023

Is this effectively the same as abstract members?

If so, what would happen if I tried to instantiate/attach a script with @mustoverride members? Does it fail?

@me2beats
Copy link
Author

yes it can be named abstract I guess, changed the title
And yes I think it should fail

@me2beats me2beats changed the title Implement mustoverride class members in GDScript Implement mustoverride/abstract class members in GDScript May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants