Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to create a new dictionary key on demand?

Asked by
voile 0
8 years ago

I am trying to have an expandable dictionary so I can store data for every player, so it has to be updated when a new player joins.

Normally, to put new data in a table, I would have to use table.insert

However, I want to more easily assign the keys to the player object, like the following:

data = {
    [player1] = { "im", "player",  "#", "3" },
    [player2] =  { "im", "player",  "#", "2" },
    [player3] =  { "im", "player",  "#", "3" }
}

makeplr = function(plr)
    -- create [plr] key in data dictionary
end

Answer this question