Hi,
I have this array below and trying to add a new item, when I run the code below I get the error attempt to index nil with number.
How do I add a new item? thanks
local test = {
{1,0},
{2,0},
{3,0}
}
table.insert(test[4][0])
Hi,
I have this array below and trying to add a new item, when I run the code below I get the error attempt to index nil with number.
How do I add a new item? thanks
local test = {
{1,0},
{2,0},
{3,0}
}
table.insert(test[4][0])
because test is the table’s variable and the first bracket [4] is the index, which is the 4th row and you don’t have a 4th index, you only have 3. That’s why it’s nil.
local test = {
{1,0},
{2,0},
{3,0}
}
table.insert(test,{4,0})
print(test[4][1],test[4][2])
table.insert is used as table.insert(reference to array, value you are inserting)
Thanks I was formatting it incorrectly.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.