File tree 1 file changed +10
-8
lines changed
tutorials/scripting/gdscript
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.
1040
1040
1041
1041
@onready var health_bar: ProgressBar = get_node("UI/LifeBar")
1042
1042
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
+
1043
1053
Alternatively, you can use the ``as `` keyword to cast the return type, and
1044
1054
that type will be used to infer the type of the var.
1045
1055
@@ -1052,12 +1062,4 @@ that type will be used to infer the type of the var.
1052
1062
1053
1063
This option is also considered more :ref: `type-safe<doc_gdscript_static_typing_safe_lines> ` than the first.
1054
1064
1055
- **Bad **:
1056
1065
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