Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Another tables and classes question

edited October 2013 in Questions Posts: 22

I am trying to put a table from one class into another class. It seems like it would be pretty straight forward but I keep getting an error, but only after it runs it's function using the table. I just ask it print the table[i] which it does but then it says it gets nil.
Here is the simple code for this test.
Thanks in advance for any help.

--# Main -- table into class test -- Use this function to perform your initial setup function setup() nTab = NewTable() useT = UseTable() end -- This function gets called once every frame function draw() -- This sets a dark background color background(40, 40, 50) -- This sets the line thickness strokeWidth(5) end --# NewTable NewTable = class() function NewTable:init() -- you can accept and set parameters here nt = {1,2,3,4,5} UseTable(nt) end --# UseTable UseTable = class() function UseTable:init(tb) -- you can accept and set parameters here for i,v in ipairs(tb) do print(tb[i]) end end


  • IgnatzIgnatz Mod
    Posts: 5,396

    The error is caused by

    useT = UseTable()

    Because UseTable expects to be given a table to print and you aren't giving it one

  • @Ignatz thank you! That makes sense once you pointed it out. Btw I've been reading you're ebook on Lua. Great stuff. I am definitely a fan.

Sign In or Register to comment.