-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add pass-by-value structs to GDScript #5130
Comments
This is probably a duplicate of #2816. I'd suggest posting your proposal there as a comment. |
I did see that proposal, which would also solve it if it involved pass by value. However that proposal is quite a bit more complex, and the pass by value is just one aspect, it is more about compactness and Variant support etc. This proposal is far more minimal - I'm primarily concerned with solving a pressing problem in the language here with something that is less controversial and easier to implement (and thus easier to get into production). Without knowing the innards of gdscript, this proposal may at a minimum just involve a small alteration to the assign operator, and if we could also add this when passing arguments this would be great. |
The proposal only mentions inner classes and structs. How would you do this on a global level? |
Describe the project you are working on
Writing testbed navmesh physics in gdscript before conversion to c++ for the engine.
Describe the problem or limitation you are having in your project
User defined classes in gdscript seem to always pass by reference rather than by value (as would c++). This is wanted in some cases, but in the case of e.g. user types like a Vector2i fixed point type, it seems that the only way to get sane behaviour is to write a
duplicate()
function manually, e.g.:And call duplicate everywhere:
Note you also have to call duplicate on parameters entering functions so you don't alter the calling data.
This causes no end of bugs because if you miss one manual duplicate, you can end up altering source data to a function (this has wasted me many hours debugging this week).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
One way around this would to be to allow the definition of
struct
as well asclass
. Thestruct
would be exactly the same asclass
, except by default it would copy by value instead of by reference.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
It would be used often, requires loads of bug prone gdscript to workaround.
Is there a reason why this should be core and not an add-on in the asset library?
Can't be implemented as addon.
The text was updated successfully, but these errors were encountered: