Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Did I use 'table.Insert' correctly?

Here is the coding

function admin()
                   if msg:sub(1,6) == "admin " and isAdmin(spkr) then
                        vic = msg:sub(1,9)
                        if findPlayer(vic) then
                            table.Insert(vic, #admins)
                    end

1 answer

✓ Accepted answer

All of the built-in Lua functions are lowercase. It's table.insert, not table.Insert.


The parameters to table.insert are (whichTable, whereInTable, whatThingToPutIn) (and the whereInTable is optional -- it defaults to the end of the table).


To add vic to the table admins, we would do

table.insert(admins, vic)

EDIT: I screwed up the order of whereInTable and whatThingToPutIn, thank you Perci1 for reminding me. (whereInTable is optional and so this mistake doesn't affect the actual code snippet here)

6 comments

0

Thanks, I will Mark this in case I forget, Thanks :D

0

Is it not table.insert(whichTable, where, whatThingToPutIn)? Where where is optional of course.

1

Can't you also do table:insert(whatThingToPutIn,where)?

0

Perci1: No. a:b(c) is sugar for a.b(a,c), which would mean all tables would require a insert property for t:insert to work; that would defy the assumption that {} has no values in it anywhere.

0

But you can do stringname:sub() instead of string.sub(), so why should it be different for this?

0

Try it out! Strings have those things built in, so it works for them -- they also don't actually have properties, it's just magic for them (("cat").sub will error)

This discussion is preserved as it was. New answers, comments, and votes are closed.