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

Make onready variables created from dropping nodes include custom types #79198

Merged
merged 1 commit into from
Jul 14, 2023

Conversation

theraot
Copy link
Contributor

@theraot theraot commented Jul 8, 2023

This pull request makes dropping a node into the script editor while holding Ctrl generate code of the form "@onready var name := $Path as Custom" "@onready var name:Custom = $Path"

Closes godotengine/godot-proposals#7239

@theraot theraot requested a review from a team as a code owner July 8, 2023 11:24
@dalexeev dalexeev requested a review from a team July 8, 2023 12:07
@dalexeev
Copy link
Member

dalexeev commented Jul 8, 2023

Personally, I prefer the option

@onready var name: Type = $Path

because the following option

@onready var name := $Path as Type

hides an error if the node has the wrong type. The object will be silently cast to null, without any error.

@dalexeev dalexeev modified the milestones: 4.x, 4.2 Jul 8, 2023
@theraot
Copy link
Contributor Author

theraot commented Jul 8, 2023

@dalexeev One one hand, that makes me think that the @onready var name: Type = $Path should be the one that makes the editor happy highlights the line number. But that is a separate issue.

I'll switch the syntax based on the pull release based on the feedback.

@theraot theraot force-pushed the enchance_onready_drop branch from d960dc2 to 3912eec Compare July 8, 2023 20:34
@theraot theraot force-pushed the enchance_onready_drop branch from 3912eec to 6a1d950 Compare July 8, 2023 22:52
@theraot theraot force-pushed the enchance_onready_drop branch 4 times, most recently from 22c9784 to cb51826 Compare July 8, 2023 23:17
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last style fix needed, otherwise seems fine.

@theraot theraot force-pushed the enchance_onready_drop branch from cb51826 to 57892ba Compare July 8, 2023 23:19
editor/plugins/script_text_editor.cpp Outdated Show resolved Hide resolved
editor/plugins/script_text_editor.cpp Outdated Show resolved Hide resolved
@theraot theraot force-pushed the enchance_onready_drop branch from 57892ba to bb2282d Compare July 9, 2023 08:47
@theraot theraot changed the title Improve onready variables created when dropping nodes into script editor and holding Ctrl Make onready variables created from dropping nodes include custom types Jul 12, 2023
@theraot theraot force-pushed the enchance_onready_drop branch from bb2282d to 93d5200 Compare July 12, 2023 12:29
@theraot theraot force-pushed the enchance_onready_drop branch from 93d5200 to a51116c Compare July 12, 2023 12:58
@YuriSizov YuriSizov merged commit c10b8ac into godotengine:master Jul 14, 2023
@YuriSizov
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make onready variables created from dropping nodes include custom types
4 participants