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

How would I add a player's name to a table?

Asked by 9 years ago

Basically, for my place, there are a set of command that high ranks in a certain group can use. However, I want to be able to let others have access to these commands by giving them commands in game. The best idea I came up with to do this is to create an empty table and add people's names to the table while I'm in game, so that whenever they speak a certain command, the script registers it. I already got the iteration part done; all I need to know is how to player names to a table. Could someone tell me how I could do this? Thanks.

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

It's very easy. Lua provides a built in function to add values to tables called table.insert(). It's pretty self explanatory.

table.insert(tableName, value)

This will place value at the end of the table, but there's also an optional argument that dictates where the value is added.

table.insert(tableName, 2, value) --Puts it at table[2].
0
Thanks! poisonmonkey 30 — 9y
Ad

Answer this question