|
| 13 Sep 2015 02:51 PM |
I can manually make a table like
table = { ["Vendicular"] = 1 }
but how do i use a script to insert something like that?
I tried:
mom = script.Parent mom.Touched:connect(function(part) table.insert(pplat, part.Parent.Name, 1) end)
and it returns: Workspace.TouchPad.Touched:5: bad argument #2 to 'insert' (number expected, got string) |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:51 PM |
local = table()
#code print ("Shots fired, ready for the war!") -- Currently working on Gui's |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 13 Sep 2015 02:52 PM |
"table.insert(pplat, part.Parent.Name, 1)" pplat[part.Parent.Name] = 1 |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:52 PM |
local tab = { ["Potatoes"] = 1; }
tab["Shrooms"] = 2;
print(tab.Shrooms) |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:52 PM |
| pplat is name of table i forgot to include it |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:53 PM |
the arguments go in the order of"
table
index #
value to insert |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:56 PM |
Expanding on my answer (Since nobody but Sensei seem to know what they are doing) The reason is, you could also do this: table[1] = blah, table[2] = blah, et cetera But what if you wanted to insert a value in between a couple of values? That's what table.insert is for. table.insert is for working with ordered lists, which use numerical indices. table.insert(Table, 5, blah) -- Inserts blah between 4 and 5, and moves everything after 4 over one Table[5] = blah -- Overwrites Table[5], causing the previous value to be lost. |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 02:58 PM |
| And since dictionaries (Tables with non-integer keys) are not ordered, table.insert doesn't work with them. |
|
|
| Report Abuse |
|
|