Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
GrimmSpector

Table not being recognized?

Question

I've got a piece of code, trying to insert some values into a table, as below.


local table1, table2, table3 = {}

function somefunction(inputtable)
  for k,v in pairs(inputtable) do
    if k == "1" then
      table.insert(table1, v)
    elseif k == "2" then
      table.insert(table2, v)
    end
  end
end

I get an error referencing one of the table insert lines, like this:

extractorController.lua:34: bad argument #1 to 'insert' (table expected, got nil)
stack traceback:
    [C]: in function 'insert'
    extractorController.lua:34: in function 'somefunction'
    [C]: in function 'xpcall'
    machine:751: in function 'xpcall'
    /lib/process.lua:78: in function </lib/process.lua:71>
stack traceback:
    [C]: in function 'error'
    /lib/process.lua:92: in function </lib/process.lua:71>

Clearly I'm defining these tables at the start of the file...so I'm not sure why this is occurring...? I'd really appreciate some help figuring this out! Thanks.

 

 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.