1-- call single argument integer constructor
2p1 = player.new(2)
3
4-- p2 is still here from being
5-- set with lua["p2"] = player(0); below
6local p2shoots = p2:shoot()
7assert(not p2shoots)
8-- had 0 ammo
9
10-- set variable property setter
11p1.hp = 545;
12-- get variable through property getter
13print(p1.hp);
14
15local did_shoot_1 = p1:shoot()
16print(did_shoot_1)
17print(p1.bullets)
18local did_shoot_2 = p1:shoot()
19print(did_shoot_2)
20print(p1.bullets)
21local did_shoot_3 = p1:shoot()
22print(did_shoot_3)
23
24-- can read
25print(p1.bullets)
26-- would error: is a readonly variable, cannot write
27-- p1.bullets = 20
28
29p1:boost()
30