summaryrefslogtreecommitdiff
path: root/modules/gdscript/tests/scripts/parser/features/bitwise_operators.gd
blob: de502c6ed1c4575840cdd71cd95db2621b96f8e2 (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
43
44
45
46
47
48
49
50
enum Flags {
	FIRE = 1 << 1,
	ICE = 1 << 2,
	SLIPPERY = 1 << 3,
	STICKY = 1 << 4,
	NONSOLID = 1 << 5,

	ALL = FIRE | ICE | SLIPPERY | STICKY | NONSOLID,
}


func test():
	var flags = Flags.FIRE | Flags.SLIPPERY
	print(flags)

	flags = Flags.FIRE & Flags.SLIPPERY
	print(flags)

	flags = Flags.FIRE ^ Flags.SLIPPERY
	print(flags)

	flags = Flags.ALL & (Flags.FIRE | Flags.ICE)
	print(flags)

	flags = (Flags.ALL & Flags.FIRE) | Flags.ICE
	print(flags)

	flags = Flags.ALL & Flags.FIRE | Flags.ICE
	print(flags)

	# Enum value must be casted to an integer. Otherwise, a parser error is emitted.
	flags &= int(Flags.ICE)
	print(flags)

	flags ^= int(Flags.ICE)
	print(flags)

	flags |= int(Flags.STICKY | Flags.SLIPPERY)
	print(flags)

	print()

	var num = 2 << 4
	print(num)

	num <<= 2
	print(num)

	num >>= 2
	print(num)