practice/lua/classes/main.lua

27 lines
726 B
Lua
Raw Normal View History

2017-05-10 15:04:18 -07:00
Player = {}
Player.__index = Player
function Player:create(health, strength)
local player = {} -- Our object
setmetatable(player, Player) -- our handle lookup
player.health = health -- initializing or stuff
player.strength = strength
return player
end
function Player:damage(damage)
self.health = self.health - damage
end
--Create our main character
player_Jack = Player:create(100, 12)
print ("Jack's current health is: "..player_Jack.health)
print ("Jack's current strength is: "..player_Jack.strength)
print ("Despite his mighty strength, Jack is still an idiot and got hit for 10 damage")
player_Jack:damage(10)
print ("Well, if he keeps this up he is going to die, his health is now: "..player_Jack.health)