aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/examples/source/player_script.lua
diff options
context:
space:
mode:
authorAndy <drumsetmonkey@gmail.com>2019-08-29 13:07:45 -0400
committerAndy <drumsetmonkey@gmail.com>2019-08-29 13:07:45 -0400
commit4ac4b280abf2ffa28caa5a532353115a3033444f (patch)
tree2a13d658bb454360b2faf401244bb0321d3460d4 /lib/sol2/examples/source/player_script.lua
parente9758416b18b27a65337c28d9641afc0ee89b34b (diff)
parent7a46fa2dd3dad3f038bf8e7339bc67abca428ae6 (diff)
Started creating scripting library/namespace and added sol2 for interfacing
Diffstat (limited to 'lib/sol2/examples/source/player_script.lua')
-rw-r--r--lib/sol2/examples/source/player_script.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sol2/examples/source/player_script.lua b/lib/sol2/examples/source/player_script.lua
new file mode 100644
index 0000000..c53a8d1
--- /dev/null
+++ b/lib/sol2/examples/source/player_script.lua
@@ -0,0 +1,29 @@
+-- call single argument integer constructor
+p1 = player.new(2)
+
+-- p2 is still here from being
+-- set with lua["p2"] = player(0); below
+local p2shoots = p2:shoot()
+assert(not p2shoots)
+-- had 0 ammo
+
+-- set variable property setter
+p1.hp = 545;
+-- get variable through property getter
+print(p1.hp);
+
+local did_shoot_1 = p1:shoot()
+print(did_shoot_1)
+print(p1.bullets)
+local did_shoot_2 = p1:shoot()
+print(did_shoot_2)
+print(p1.bullets)
+local did_shoot_3 = p1:shoot()
+print(did_shoot_3)
+
+-- can read
+print(p1.bullets)
+-- would error: is a readonly variable, cannot write
+-- p1.bullets = 20
+
+p1:boost()