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