I am having trouble using a metatable to create new monsters for a game, I can create an exact copy but I can't generate a new rat or lizard for example with a new id.
local monsters = {
rat = {
name = "a rat",
id = 1,
health = 5,
}
lizard = {
name = "a lizard",
id = 1,
health = 8,
}
}
local metamonsters = {__index = monsters}
setmetatable(monsters, metamonsters)
function monsters:new(o)
setmetatable(o, metamonsters)
return o
end
local testrat = monsters:new({rat})
print(testrat.name, testrat.id)
This creates a new rat under the variable testrat, and the console prints "a rat" and "1". I can't work out how to specify a new id number for the rat when its created. Any help would be appreciated, metatables are confusing me like mad!