Lua - Attempt to index local 'item' (a function value) -
i'm getting error, , can't figure out if it's scoping issue, logic issue, or else entirely. objective, in c terms, modify pointer within module change behavior of draw() command. place error coming is:
function m.draw() k, item in pairs(m.buttons.current) love.graphics.setcolor(m.buttons.bkg_color) love.graphics.rectangle("fill", item.pos_x, item.pos_y, m.buttons.size_x, m.buttons.size_y) love.graphics.setcolor(m.buttons.txt_color) --todo: center text on button love.graphics.print(item.text, item.pos_x+10, item.pos_y+10) end end
this function works in first menu, when click button change menus, error pops in love.graphics.rectangle(...) line. code changes m.buttons.current is:
function m.mousereleased(x, y, button) if button == 'l' , m.buttons.buttonpressedflag , m.mousecollide(x,y,m.buttons.buttonpressed) m.buttons.buttonpressed.fun() end m.buttons.buttonpressedflag = false end
and button i'm clicking defined during initialization using:
m.formbutton( m.buttons.main, "options", global_settings.resolution_x/2-m.buttons.size_x, global_settings.resolution_y/7*5-m.buttons.size_y, m.buttons.size_x, m.buttons.size_y, "options", function() m.buttons.current = m.buttons.main.options end )
where m.formbutton defined @ top of module:
function m.formbutton(menu, buttonname, pos_x, pos_y, size_x, size_y, text, fun) menu[buttonname].pos_x = pos_x menu[buttonname].pos_y = pos_y menu[buttonname].size_x = size_x menu[buttonname].size_y = size_y menu[buttonname].text = text menu[buttonname].fun = fun end
each of buttons should in new menu defined similarly. reference, prototype of module's structure is:
local m = {buttons = { main = { campaign = { newgame = {}, continue = {}, load = {}, = {} }, freeplay = { newgame = {}, continue = {}, load = {}, custom = {}, = {} }, multiplayer = { lan = { newgame = {}, load = {}, = {}, }, hotseat = { newgame = {}, load = {}, = {}, }, network = { newgame = {}, load = {}, = {} } }, options = { audio = {}, display = {}, gameplay = {}, language = {} }, exitgame = {} } } }
i'm pretty sure issue coming the third line in mousereleased function combined way i've instantiated button, can't figure out issue is. it's distressingly simple i'm missing because i'm new language, appreciated.
you're overriding m.buttons.options
or m.buttons.current
somewhere, changing function value. try adding print(type(m.buttons.current), type(m.buttons.options))
periodically between function calls - should able narrow down offending code.
Comments
Post a Comment