I’m working between two files at the moment. The first being:
module = {} function module:load() module.currentMenu = "main" local menu = nil local gui = display.newGroup() local rect = display.newRect(0, 0, display.contentWidth, 80) rect.alpha = 100/255 local line = display.newLine(0, 80, 568, 80) line.width = 3 line.alpha = 150/255 gui:insert(rect) gui:insert(line) module.update = function() if (module.currentMenu == "main") then rect.x = 0 rect.y = 0 rect.width = display.contentWidth\*2 rect.height = 160 line.x1 = 0 line.x2 = display.contentWidth line.y1 = 80 line.y2 = 80 menu = require("scripts.gui.gui\_menu\_main") menu.load(module) elseif (module.currentMenu == "material") then rect.x = 0 rect.y = 0 rect.width = display.contentWidth rect.height = display.contentHeight line.x1 = 0 line.x2 = display.contentWidth line.y1 = display.contentHeight line.y2 = display.contentHeight menu = require("scripts.gui.gui\_menu\_material") menu.load(module) end end module.update() end return module
and the second being:
module = {} local button = require("scripts.gui.gui\_button") function module.load(editor) local menu = display.newGroup() print(editor.currentMenu) local material = button.new(-15 + display.contentWidth/7.5, 40, "material", function() editor.currentMenu = "material" editor.update() return true end) local up = button.new(-15 + display.contentWidth/7.5\*2, 40, "up", function() print("up clicked") return true end) local down = button.new(-15 + display.contentWidth/7.5\*3, 40, "down", function() print("down clicked") return true end) local object = button.new(-15 + display.contentWidth/7.5\*4, 40, "rock", function() print("object clicked") return true end) local entity = button.new(-15 + display.contentWidth/7.5\*5, 40, "entity", function() print("entity clicked") return true end) local size = button.new(-15 + display.contentWidth/7.5\*6, 40, "scale", function() print("size clicked") return true end) local save = button.new(-15 + display.contentWidth/7.5\*7, 40, "save", function() print("save clicked") return true end) end return module
My issue is that when I click the ‘material’ button, it’s saying “attempt to call field ‘update’ (a nil value)”
Can somebody explain to me why this is happening? I’m somewhat new to lua, but have plenty of programming experience.
Also, the module from the first class is not getting properly put through to the second class
print(editor.currentMenu) is printing ‘nil’
How can I properly pass the module of the first class to the second class?
Edit: If needed, I can provide the entire project