Debian Codegraph @

modules/gdscript/tests/scripts/parser/features/property_setter_getter.gd

raw
1 # 4.0+ replacement for `setget`:
2 var _backing: int = 0
3 var property:
4 get:
5 return _backing + 1000
6 set(value):
7 _backing = value - 1000
8
9 var property_2:
10 get(): # Allow parentheses.
11 return 123
12
13 func test():
14 print("Not using self:")
15 print(property)
16 print(_backing)
17 property = 5000
18 print(property)
19 print(_backing)
20 _backing = -50
21 print(property)
22 print(_backing)
23 property = 5000
24 print(property)
25 print(_backing)
26
27 # In Godot 4.0 and later, using `self` no longer makes a difference for
28 # getter/setter execution in GDScript.
29 print("Using self:")
30 print(self.property)
31 print(self._backing)
32 self.property = 5000
33 print(self.property)
34 print(self._backing)
35 self._backing = -50
36 print(self.property)
37 print(self._backing)
38 self.property = 5000
39 print(self.property)
40 print(self._backing)
41
42 print(property_2)