View difference between Paste ID: rkUGhkJR and PR1hGYDC
SHOW: | | - or go back to the newest paste.
1-
local classes = {
1+
2-
	fighter = {
2+
	local classes = {
3-
		health = 100, --default health
3+
		fighter = {
4-
		takeDamage = function(self, amount)
4+
			health = 100, --default health
5-
			self.health = self.health - amount >= 1 and self.health - amount or 0
5+
			takeDamage = function(self, amount)
6-
		end
6+
				self.health = self.health - amount >= 1 and self.health - amount or 0
7
			end
8-
}
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-
print(enemy.health) --this will print 50 because the health changed
18+
19
local x = new("fighter")
20
print(x.health)