[Help] Attempt to get length of field (a nil value)
Posted: Fri Sep 26, 2014 8:30 pm
So, I'm making a constructor for draw lists and I have a table in the constructor (not the object that the constructor returns). Whenever I try to access the table, it comes up as non-existent. The constructor returns an object without a problem, however when I try to access the table, I get the error.
Now, I am a bit of a beginner when it comes to Lua, so I apologize if the problem is something overly simple, however, this is the longest I've ever been stuck in programming.
Now, I am a bit of a beginner when it comes to Lua, so I apologize if the problem is something overly simple, however, this is the longest I've ever been stuck in programming.
Code: Select all
local DrawList = {}
function DrawList.newDrawList()
this = {}
this.queue = {} -- This is the table
print(#this.queue) -- Prints 0
function this.add(image)
print(#this.queue) -- Error
this.queue[#this.queue+1] = image
image.drawNum = #this.queue
end
return this
end
return DrawList