We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
A behavior tree library
I'd like to create some const Callable members of a class. This seems to be impossible in GDScript at the moment.
So I'd like to be able to write
enum Status { SUCCESS, RUNNING, FAILURE } const policy_run_until_success:Callable = func(status:Status): return status == Status.SUCCESS
At the moment this is causing the error Assigned value for constant "policy_run_forever" isn't a constant
Assigned value for constant "policy_run_forever" isn't a constant
This does work:
enum Status { SUCCESS, RUNNING, FAILURE } var policy_run_until_success:Callable = func(status:Status): return status == Status.SUCCESS
However, it is not a constant so it can be overwritten. The main point of this is so that I can use it as a default value in the class's constructor:
var policy:Callable func _init(_policy:Callable = policy_run_until_success): policy = _policy
It allows you to create libraries of lambda functions that you can then use elsewhere.
Update GDScript so that lambda functions can be assigned to const fields.
No, since var fields can be overwritten and cannot be used as default parameter values.
var
Requires changing GDScript.
The text was updated successfully, but these errors were encountered:
Note that function parameters support non-constant default values.
Sorry, something went wrong.
No branches or pull requests
Describe the project you are working on
A behavior tree library
Describe the problem or limitation you are having in your project
I'd like to create some const Callable members of a class. This seems to be impossible in GDScript at the moment.
So I'd like to be able to write
At the moment this is causing the error
Assigned value for constant "policy_run_forever" isn't a constant
This does work:
However, it is not a constant so it can be overwritten. The main point of this is so that I can use it as a default value in the class's constructor:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
It allows you to create libraries of lambda functions that you can then use elsewhere.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Update GDScript so that lambda functions can be assigned to const fields.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, since
var
fields can be overwritten and cannot be used as default parameter values.Is there a reason why this should be core and not an add-on in the asset library?
Requires changing GDScript.
The text was updated successfully, but these errors were encountered: