lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I've released another version of the module. The player.all_kills table itself works, but still don't know how to print it all to the dialog...

2013-12-03 13:49 GMT+01:00 Michal Kolodziejczyk <>:
On 03.12.2013 12:54, K M wrote:

>  player.all_kills[] =  player.all_kills[] or 0
>  player.all_kills[] =  player.all_kills[] + 1
>         end

The above can be rewritten as:
  player.all_kills[] = ( player.all_kills[] or 0 ) + 1

> 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.

Probably because of mistake below:

> The idea is to have
> "orc -".. player.all_kills[orc]
> without hardcoding it for every creature possible in my game.

That should be:

"orc -".. player.all_kills["orc"]

or (equivalent):

"orc -".. player.all_kills.orc

> Heelp?

Try this:
player.all_kills={orc=12, dragon=5, hero=2}

player.all_kills=setmetatable(player.all_kills, {
    local buf={}
    for k,v in pairs(self) do
    return table.concat(buf, ' ')


Works in pure lua, don't know about the version in this game engine.