How to create a level selection menu with tables?

I keep get errors with this code and i don’t know how to fix it. I know it is something to do with my touch listener. I have been trying to fix it for a day and a half. Aka I am very new to the forms.

local background = display.newRect( display.contentCenterX, display.contentCenterY, 480, 320 ) background:setFillColor( 0,.8,.1 ) local levels = { {level= 1, image = "images/1.png", x = 50, y = 50}, {level= 2, image = "images/2.png", x = 150, y = 50} } -- functions function tapOnlevel( self, event ) local whatLevel = "level"..self.name if (event.phase == "began") then composer.removeScene("levelSelect") composer.gotoScene(whatLevel) end end for i=1,#levels do local whereIsit = levels[i].level levelImage = display.newImage( "images/"..whereIsit..".png", levels[i].x , levels[i].y) levelImage.name= "levelImage"..i print( levelImage.name ) levelImage:addEventListener( "touch", tapOnlevel ) end

Error is attached

There are two ways to do event listeners:   table listeners, and function listeners.  You are trying to blend the two.  Personally I find function listeners easier to deal with than function listeners and this will be easy for you to fix if you use a function listener.

Simply take the "self, " out of the function declaration.  That part is needed for table listeners.  The rest of your code is setup as a function listener, so try removing it.

Welcome to the forums.

Rob

There are two ways to do event listeners:   table listeners, and function listeners.  You are trying to blend the two.  Personally I find function listeners easier to deal with than function listeners and this will be easy for you to fix if you use a function listener.

Simply take the "self, " out of the function declaration.  That part is needed for table listeners.  The rest of your code is setup as a function listener, so try removing it.

Welcome to the forums.

Rob