0
votes

I was working on this project about a year ago. I came back to it and now it throws an error when I run it the error is "attempt call field "drawers"(a table value)".

This is where the drawers field is

local Renderer = {}

local num_of_layers = 2
local insert = table.insert
local remove = table.remove


function Renderer:create()
    local render = {}

    render.drawers = {}
    for i  = 0, num_of_layers do
        render.drawers[i] = {}
    end

    function render:addRenderer(obj, layer)
        local l = layer or 0
        insert(self.drawers(l), i, obj)
    end

    return render
end

return Renderer

This is where it is being called

local tlm = {}

function tlm:load()
     renderer:addRenderer(self)
     gameloop:addLoop(self)
end
1
It's a bit confusing with the uppercase Renderer and the lowercase renderer, and the function Renderer:create doesn't actually have an end, from our point of view. Could you make the code a little clearer? - user6245072
Also, spotted the error. drawers is actually a table containing some tables, but you're calling it passing l as an argument from renderer:addRenderer. Again, I can't understand what you wanted to do. - user6245072

1 Answers

0
votes

This is not correct:

insert(self.drawers(l), obj)

self.drawers is not a function but a table. therefor a function call like self.drawers(1) results in an error.

If you wanted to insert an element to the table self.drawers at index l using Luas standard functions you should call:

table.insert(self.drawers, i, obj)

If you want to replace the value at index l you can simply write self.drawers[l] = obj

http://www.lua.org/manual/5.3/manual.html#pdf-table.insert