Skip to content

Commit 4b74581

Browse files
committed
Updated description of static variables for traits
1 parent be35be0 commit 4b74581

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

tutorials/scripting/gdscript/gdscript_basics.rst

+9-15
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ Static variables belong to the class or trait, not instances. This means that st
11321132
share values between multiple instances, unlike regular member variables.
11331133

11341134
From inside a class or trait, you can access static variables from any function, both static and non-static.
1135-
From outside the class or trait, you can access static variables using the class/trait or an instance
1135+
From outside the class or trait, you can access static variables using the class or an instance
11361136
(the second is not recommended as it is less readable).
11371137

11381138
.. note::
@@ -1203,23 +1203,17 @@ A base class static variable can also be accessed via a child class::
12031203
B.x = 3
12041204
prints(A.x, B.x) # 3 3
12051205

1206-
.. warning::
1207-
1208-
Static variables declared on traits belong to the trait *itself*, and are *not*
1209-
inherited by classes that use the trait::
1206+
Likewise, if a class uses a trait with static variables, it will inherit those
1207+
variables::
12101208

1211-
trait HasStatic:
1212-
static var static_var = 3
1209+
trait HasStatic:
1210+
static var static_var = 3
12131211

1214-
class UsingClass:
1215-
uses HasStatic
1212+
class UsingClass:
1213+
uses HasStatic
12161214

1217-
func _ready():
1218-
# Will work
1219-
print(HasStatic.static_var)
1220-
1221-
# Will NOT work, as UsingClass does not get static_var from HasStatic
1222-
print(UsingClass.static_var)
1215+
func _ready():
1216+
print(UsingClass.static_var)
12231217

12241218
``@static_unload`` annotation
12251219
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)