File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
tutorials/scripting/gdscript Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -1040,6 +1040,16 @@ should set the type explicitly.
10401040
10411041 @onready var health_bar: ProgressBar = get_node("UI/LifeBar")
10421042
1043+ **Bad **:
1044+
1045+ .. rst-class :: code-example-bad
1046+
1047+ ::
1048+
1049+ # The compiler can't infer the exact type and will use Node
1050+ # instead of ProgressBar.
1051+ @onready var health_bar := get_node("UI/LifeBar")
1052+
10431053Alternatively, you can use the ``as `` keyword to cast the return type, and
10441054that type will be used to infer the type of the var.
10451055
@@ -1052,12 +1062,4 @@ that type will be used to infer the type of the var.
10521062
10531063This option is also considered more :ref: `type-safe<doc_gdscript_static_typing_safe_lines> ` than the first.
10541064
1055- **Bad **:
10561065
1057- .. rst-class :: code-example-bad
1058-
1059- ::
1060-
1061- # The compiler can't infer the exact type and will use Node
1062- # instead of ProgressBar.
1063- @onready var health_bar := get_node("UI/LifeBar")
You can’t perform that action at this time.
0 commit comments