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

Abstract keyword for scripts #6319

Closed
GianptDev opened this issue Feb 19, 2023 · 1 comment
Closed

Abstract keyword for scripts #6319

GianptDev opened this issue Feb 19, 2023 · 1 comment

Comments

@GianptDev
Copy link

Describe the project you are working on

.

Describe the problem or limitation you are having in your project

.

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

Can the engine implement abstract classes/scripts like other languages such as java do?

It can help the user to tell the user a specific class is a base class not intended to be used but only to be extended.

It could be implemented adding the abstract keyword to a script like tool does, and should:

  • not allow to instance the script with new()
  • allow to load the script using load(), preload(), or globally via class_name
  • allow to extend the script and when extended abstraction is removed in the new script unless is define again.

Can be used to make a parent class that define only the base code of sub-classes and allow only those sub-classes to be used.

Action (abstract)
├── ActionMove
├── ActionScale
└── ActionRotate

Here an example of a robot that could move by a list of actions, adding actions like movement and rotation makes sense:

var robot: = MovableThing.new();
robot.add_movements(
    ActionMove.new(12, 0), # move the thing by 12 on x axys.
    ActionRotate.new(90),   # rotate the thing
    Action.new() # empty action, it does nothing and we could tell the used this is useless.
);

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

The keyword could be used like this:

# script marked as abstract, cannot be instanced.
abstract class_name SomeClass extends Object;
# ...

Will prevent to instance the abstract class.

SomeClass.new(); # this will result in an error.

But allow extends:

class_name AnotherClass extends SomeClass;
# abstraction resetted.

And can be used to implement a list of global constant properties and mark that instancing this object is useless.

abstract class_name Globals extends Object;

const foo = "bar";
# ...

Maybe even adding a function to the Script object to check if the script has the abstract flag:

var someScript: Script = load("path/to/script.gd");
someScript.is_abstract(); # true of false.

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

.

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

yes

@Mickeon
Copy link

Mickeon commented Feb 19, 2023

Duplicate of #5641.

@YuriSizov YuriSizov closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 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

4 participants