ForeverDev

Untitled

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