ForeverDev

Untitled

Sep 7th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. local classes = {
  2.     fighter = {
  3.         health = 100, --default health
  4.         takeDamage = function(self, amount)
  5.             self.health = self.health - amount >= 1 and self.health - amount or 0
  6.         end
  7.     }
  8. }
  9.  
  10. local new = function(type)
  11.     return classes[type:lower()]
  12. end
  13.  
  14.  
  15. local enemy = new("fighter")
  16. print(enemy.health) --this will print 100, because the default health is 100
  17. enemy:takeDamage(50) --make the enemy take 50 damage
  18. print(enemy.health) --this will print 50 because the health changed
Advertisement
Add Comment
Please, Sign In to add comment