Zio_Pagnotta
Zio_Pagnotta

Reputation: 43

update table value while iterating

i'm currently learning LUA. My question is how to change the value in a table, i got nil:

my table is:

local players = {
  {name = something, count = 1}
}

for _, current in ipairs(players) do
    if current.name == inflictor.name then
        local count = players[current].count   --NIL
        players[current].count = count + 1
        break
    end
end

thanks for the help

Upvotes: 1

Views: 966

Answers (1)

user10133166
user10133166

Reputation:

In your ipairs loop, _ is the key and current is the value, which in this case is that table inside your players table.

You'd fix that if you set either: players[_].count or just current.count

Upvotes: 2

Related Questions