Page 2 of 2

Re: Basic concepts of OOP

Posted: Thu Feb 16, 2012 6:10 pm
by coffee
thelinx wrote:You just define enemy.add as
...
waraiotoko wrote: Agreed!

Code: Select all

function enemy:add(args)
	local enemy = {}
	enemy.race = args.race or "Human"
	enemy.hp = args.hp or "15"
	enemy.weapon = args.weapon or "Dagger"
	table.insert (enemies,enemy)
end
Thank you both. Always learning a bit more. Wasn't working till I realized that self (enemy in my case) shouldn't be there. I did knew "unpack" function(...) with then a local pack = {...} but nothing like this. Again I bow to you. :)