Problem Description: The program seems to not be able to identify that I’m trying to insert the button into the group when I have defined a ‘filename’ so that it goes to the specific location and retrieves the file, in order to make programming much easier. I understand Lua is Lexical scoped but, it keeps on coming up with errors (which I’ll place in a screenshot below code)
local function newMenuEffect(color) local effect = display.newRect(0,0,98,24) if type(color) == "table" then effect:setFillColor(color[1], color[2], color[3]) else effect:setFillColor(gray) end local function insertGroup(group) group:insert(effect) end local function removeGroup(group) group:remove(effect) end return effect end local function newMenuButton(filename, text) local menuButton = display.newGroup() -- if filename ~= nil then local menuButtonImage = display.newImage(filename) menuButton:insert(menuButtonImage) else local menuButtonImage = display.newImage("Menu/buttonBlue.png") menuButton:insert(menuButtonImage) end -- if text ~= nil then local menuButtonText = display.newText(text, 0, 0, "Courier New", 15 ) menuButton:insert(menuButtonText) end -- local function eventTouch(event) local effect = newMenuEffect() if ( event.phase == "began" ) then effect:insertGroup(event.target) print("DEBUG: Touch event began") elseif ( event.phase == "ended" ) then effect:removeGroup(event.target) effect = nil print("DEBUG: Touch event ended") end return true -- Prevents tap/touch propagation to underlying objects end menuButton:addEventListener("touch", eventTouch) return menuButton end local function mainStart() local menu = display.newGroup() local menuBackground = display.newImage('Menu/menuBackground.png') menu:insert(menuBackground) menu.x = display.contentCenterX menu.y = display.contentCenterY local startGame = newMenuButton("Menu/blueButton.png", "Start Game") local endGame = newMenuButton("Menu/redButton/png", "End Game") menu:insert(startGame) menu:insert(endGame) endgame.y = menubackground.height\*0.4 stargame.y = -(menuBackground.height\*0.3) end mainStart()