File: static_variables_2.gd

package info (click to toggle)
godot 4.4.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 229,428 kB
  • sloc: cpp: 1,657,504; ansic: 186,969; xml: 153,923; cs: 36,104; java: 29,122; python: 15,230; javascript: 6,211; yacc: 4,115; pascal: 818; objc: 459; sh: 459; makefile: 109
file content (56 lines) | stat: -rw-r--r-- 911 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@static_unload

class A:
	static var x: int = 1

	static var y: int = 42:
		set(_value):
			print("The setter is NOT called on initialization.") # GH-77098 p.1

	static func _static_init() -> void:
		prints("A _static_init begin:", x)
		x = -1
		prints("A _static_init end:", x)

	static func sf(p_x: int) -> void:
		x = p_x
		prints("sf:", x)

	# GH-77331
	func f(p_x: int) -> void:
		x = p_x
		prints("f:", x)

class B extends A:
	static func _static_init() -> void:
		prints("B _static_init begin:", x)
		x = -2
		prints("B _static_init end:", x)

	static func sg(p_x: int) -> void:
		x = p_x
		prints("sg:", x)

	func g(p_x: int) -> void:
		x = p_x
		prints("g:", x)

	func h(p_x: int) -> void:
		print("h: call f(%d)" % p_x)
		f(p_x)

func test():
	prints(A.x, B.x)
	A.x = 1 # GH-77098 p.2
	prints(A.x, B.x)
	B.x = 2
	prints(A.x, B.x)

	A.sf(3)
	B.sf(4)
	B.sg(5)

	var b := B.new()
	b.f(6)
	b.g(7)
	b.h(8)