Vice City: Multiplayer

Server Development => Scripting and Server Management => Script and Content Requests => Topic started by: Kenneth Law on Apr 06, 2021, 12:21 PM

Title: How to add a new key and value for a table?
Post by: Kenneth Law on Apr 06, 2021, 12:21 PM
Give a situation that I have localed a table like
local table = { "a": 1, "b": 2, "c": 3 };
How can I add a new key and a new value for it then?
For example a new key which is "d" and a new value which is 4 so that the table will become { "a": 1, "b": 2, "c": 3, "d": 4 };
Title: Re: How to add a new key and value for a table?
Post by: Spiller on Apr 06, 2021, 02:10 PM
The easiest way should be

table["d"] <- 4
You can also use table.rawset
http://www.squirrel-lang.org/squirreldoc/reference/language/builtin_functions.html#table.rawset