-
-
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
Make onready variables created from dropping nodes include custom types #7239
Comments
Yes, the green lines indicate the type safety of the code. But they do not mean that the code is better or more reliable. Note from the PR discussion: The problem with this option is that it hides an error if the node in the scene is of the wrong type (for example, the user changed the type of the node in the scene but forgot to update the type hint in the script). The |
But it is better because it has auto complete for class functions and properties. |
@Deozaan If you're using a static type, there will be autocompletion too. I compared options 1 and 2, not 2 or 3 and 4. @onready var option_1: Type = $Node
@onready var option_2 := $Node as Type
@onready var option_3 = $Node as Type
@onready var option_4 = $Node |
I've seen plenty of people say they don't get autocompletion, and I have struggled with it myself. I have now realized we have been conveying the problem wrong. It is not that we don't get autocompletion. We get autocompletion. It is that we don't get the members of the custom type in autocompletion. |
@theraot Yes, there are bugs with autocompletion, but I don't think it changes what I wrote above. Even if in some cases the If you notice an unreported bug with autocompletion, please open an issue. This proposal is closed and is not intended to discuss bugs. Thanks! |
Describe the project you are working on
3D platformer with some cross-genre mechanics
Describe the problem or limitation you are having in your project
When I drag a Node into the script editor while holding Ctrl, I get something like this:
But even if the Node has a script attached with a
class_name
I still get the same. Which is a problem because it means I don't get auto-completion for the members of my script.Furthermore, apparently it is not type safe (notice the pale line number):
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I want Godot to look if the dragged Node has a script and if that script is in the global lists of class and use that to generate - if possible - code like this:
That way I get auto-completion for the members defined in my custom class.
Also notice the line number is not pale:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
We try to get the reference to the script attached to Node being dragged, and it is not null, we try to look into
get_global_class_list
to see if it is there, and if it is, use the class name from there in the generated code.And also change the format of the generated code to match the example shown above.
If this enhancement will not be used often, can it be worked around with a few lines of script?
It cannot be done via scripting. Plus, I believe this will be used often.
Is there a reason why this should be core and not an add-on in the asset library?
Again, it is not possible to accomplish via scripting. Creating onready variables when dropping nodes into script editor and holding Ctrl is a core feature.
The text was updated successfully, but these errors were encountered: