-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allow cyclic references #460
Comments
Related to godotengine/godot#21461. There are plans to solve this in 4.0. |
I had the same issue yesterday. Overriding the get_class() function and use that to check if itself is of a certain type. Not sure if performance is well for this but at least I could get rid of cyclic reference warnings while keeping most of my types. |
I think this can be closed, since we will solve this anyway and there's already an issue being tracked in the main repository. |
Isn't that issue about a specific problem related to |
Closing for now, Duplicate of godotengine/godot#21461 |
Another instance of (future) cyclic references which can happen while serializing GDScript instances: godotengine/godot#33137 (currently just errors out without crashing at least). 😛 |
@akien-mga Re-open this since we are migrating to proposals? |
There's no need to reopen, the issue is already tracked in the main repo as a bug. |
From that issue:
So isn't that unrelated? |
@nathanfranke the issue evolved from the initial description to cover all cases. Don't worry, what's in this proposal will also be allowed. |
I agree Edit: We should still keep godotengine/godot#21461 open since it seems to be a separate bug. |
Question: Does this mean that prior to 4.0 I need to be careful of circular refs in C# when using |
In case this is helpful for anyone, I've been using a hacky workaround instead of the "is" or "as" keywords... |
Does 4.0 have this? If so can we get a backport to v3.4.5 along side custom resource exports? |
It does, but only to a limited extent as there are still some bugs with the current implementation.
No, as this change relies on a complete rewrite of GDScript (which is backwards-incompatible). Also, patch releases don't get any new features to reduce the risk of introducing regressions. |
I would love to see this! I'm working on a RogueLike which features randomly generated interconnected rooms, which are basically a linked list or graph. A Room has 0-3 Doors which reference another room. So of course my cyclic reference is Room->Door->Room. Or more simply Room->Room.
I circumvented the problem with load(), but the code gets less readable and weird. I can fully understand runtime circular instancing problems, but in this case the class that is already loaded shouldn't be loaded again causing recursive loading. There are some ways to make it work without a linked list, but they are harder to understand and less flexible. |
Should be resolved as of godotengine/godot#67714 |
Will this be backported for 3.x? |
@Lilith-In-Starlight This is not a change that can be backported. It needs to be redone completely for a 3.x branch, and that's unlikely, unfortunately. |
Describe the project you are working on:
Describe the problem or limitation you are having in your project:
Use Case: Packets
Static constructor wrappers are impossible to make due to
Parser Error: Using own name in class file is not allowed (creates a cyclic reference)
Consider the following code
It is impossible to make a static packet constructor wrapper for this since PacketPing refers to itself
Use Case: Scripts in a hierarchy
What I don't understand: Cyclic references work fine in almost every other programming language
Cyclic references that work fine in 5 of the most popular programming languages
C#:
Java:
C++:
JavaScript:
Python:
PHP: It should be noted that cyclic references actually do not work in PHP
Describe how this feature / enhancement will help you overcome this problem or limitation:
Cyclic references are completely valid for good code. It is needed to make named, static, wrapped constructors.
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
GDScript code samples above would run without errors since cyclic references should be valid
Describe implementation detail for your proposal (in code), if possible:
Cyclic references cannot be implemented without changing the scripting engine
If this enhancement will not be used often, can it be worked around with a few lines of script?:
No, right now there is no good way to work around cyclic references.
is
operator can be worked around by comparing the script withload()
Is there a reason why this should be core and not an add-on in the asset library?:
This can not be worked around with an addon. Cyclic references are a core part of the scripting engine
The text was updated successfully, but these errors were encountered: