From 57a9ef3fea7a9e817ed29aff82e49df043b6f10d Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Fri, 4 Feb 2022 19:33:10 +0100 Subject: [PATCH] Add @ to onready annotated variables in examples --- tutorials/best_practices/godot_interfaces.rst | 6 +++--- .../scripting/gdnative/gdnative_c_example.rst | 2 +- .../scripting/gdscript/gdscript_styleguide.rst | 14 +++++++------- tutorials/scripting/nodes_and_scene_instances.rst | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tutorials/best_practices/godot_interfaces.rst b/tutorials/best_practices/godot_interfaces.rst index 79a8417cf..5786faa6a 100644 --- a/tutorials/best_practices/godot_interfaces.rst +++ b/tutorials/best_practices/godot_interfaces.rst @@ -140,12 +140,12 @@ Nodes likewise have an alternative access point: the SceneTree. print($Child) # Fastest. Doesn't break if node moves later. - # Note that `onready` keyword is GDScript only. + # Note that `@onready` annotation is GDScript only. # Other languages must do... # var child # func _ready(): # child = get_node("Child") - onready var child = $Child + @onready var child = $Child func lookup_and_cache_for_future_access(): print(child) @@ -469,7 +469,7 @@ accesses: # parent.gd extends Node - onready var child = $Child + @onready var child = $Child func _ready(): child.fn = funcref(self, "print_me") diff --git a/tutorials/scripting/gdnative/gdnative_c_example.rst b/tutorials/scripting/gdnative/gdnative_c_example.rst index 48d00486b..998f4598f 100644 --- a/tutorials/scripting/gdnative/gdnative_c_example.rst +++ b/tutorials/scripting/gdnative/gdnative_c_example.rst @@ -543,7 +543,7 @@ Now we can implement our ``main.gd`` code: extends Control # load the Simple library - onready var data = preload("res://bin/simple.gdns").new() + @onready var data = preload("res://bin/simple.gdns").new() func _on_Button_pressed(): $Label.text = "Data = " + data.get_data() diff --git a/tutorials/scripting/gdscript/gdscript_styleguide.rst b/tutorials/scripting/gdscript/gdscript_styleguide.rst index 4fe33096b..5e75c5dd7 100644 --- a/tutorials/scripting/gdscript/gdscript_styleguide.rst +++ b/tutorials/scripting/gdscript/gdscript_styleguide.rst @@ -38,8 +38,8 @@ Here is a complete class example based on these guidelines: export var initial_state = NodePath() var is_active = true setget set_is_active - onready var _state = get_node(initial_state) setget set_state - onready var _state_name = _state.name + @onready var _state = get_node(initial_state) setget set_state + @onready var _state_name = _state.name func _init(): @@ -772,8 +772,8 @@ variables, in that order. var _speed = 300.0 - onready var sword = get_node("Sword") - onready var gun = get_node("Gun") + @onready var sword = get_node("Sword") + @onready var gun = get_node("Gun") .. note:: @@ -887,7 +887,7 @@ should set the type explicitly. :: - onready var health_bar: ProgressBar = get_node("UI/LifeBar") + @onready var health_bar: ProgressBar = get_node("UI/LifeBar") Alternatively, you can use the ``as`` keyword to cast the return type, and that type will be used to infer the type of the var. @@ -896,7 +896,7 @@ that type will be used to infer the type of the var. :: - onready var health_bar := get_node("UI/LifeBar") as ProgressBar + @onready var health_bar := get_node("UI/LifeBar") as ProgressBar # health_bar will be typed as ProgressBar This option is also considered more :ref:`type-safe` than the first. @@ -909,4 +909,4 @@ This option is also considered more :ref:`type-safe