|
On 03.12.2013 12:54, K M wrote:The above can be rewritten as:
> player.all_kills[self.name] = player.all_kills[self.name] or 0
> player.all_kills[self.name] = player.all_kills[self.name] + 1
> end
player.all_kills[self.name] = ( player.all_kills[self.name] or 0 ) + 1
Probably because of mistake below:
> So it stores every kill in a table entry named after the creature killed.
>
> I've tried to display the kill count in various ways, but none work.
That should be:
> The idea is to have
>
> "orc -".. player.all_kills[orc]
> without hardcoding it for every creature possible in my game.
or (equivalent):
"orc -".. player.all_kills["orc"]
"orc -".. player.all_kills.orc
> Heelp?
Try this:
player.all_kills={orc=12, dragon=5, hero=2}
player.all_kills=setmetatable(player.all_kills, {
__tostring=function(self)
local buf={}
for k,v in pairs(self) do
buf[#buf+1]=k..'-'..v
end
return table.concat(buf, ' ')
end
})
print(player.all_kills)
Works in pure lua, don't know about the version in this game engine.
Regards,
miko