Assigning a scene to each button on a for loop?

How to assign a scene to each button on a for loop? My application consist of a for loop that contains 4 buttons and its on a table.lua. What i really wanted to happen is to assign individual scene to each of the buttons from the table.

operationMenu.lua buttonTapped = function(event) local t = event.target local category = t.category if category ~= nil and touchEnabled == true then utils.playSound("select") composer.gotoScene( "scenes.difficultyMenuAddition", {effect="slideLeft", time=300, params={category=category}}) end return true end for i=1, #operations do local colour = operations[i].colour local y = (i-0.5)\*(categoryHeight+categoryOffset) + (categoryHeight/1) local textX = 36 local textW = \_W-(textX\*2) - 64 -- an extra 64 for icons local rect = display.newRect(\_W\*0.5, y, \_W, categoryHeight ) rect:setFillColor(colour[6], colour[3], colour[2]) rect.category = i rect:addEventListener("tap", buttonTapped) uiGroup:insert(rect) local arrow = display.newSprite(utils.uiSheet, {frames={utils.uiSheetInfo:getFrameIndex("arrow")}}) arrow.x = arrow.width/2 + 4 arrow.y = rect.y uiGroup:insert(arrow) local mainFont = "gomarice\_kaiju\_monster\_0.ttf" local title = display.newText({text=operations[i].title, x=textX, y=rect.y-6, width=textW, height=0, font=mainFont, fontSize=100}) title.anchorX = 0 title:setFillColor(1) uiGroup:insert(title) if operations[i].icon and operations[i].icon ~= "" then local icon = display.newSprite(utils.uiSheet, {frames={utils.uiSheetInfo:getFrameIndex(operations[i].icon)}}) icon.x = \_W - 40 icon.y = rect.y uiGroup:insert(icon) end end end

table.lua local M = { { title = "Addition", colour = {245/255, 147/255, 49/255}, icon = "icon\_general", }, { title = "Subtraction", colour = {240/255, 101/255, 47/255}, icon = "icon\_cinema", timePerQuestion = 20, }, { title = "Multiplication", colour = {126/255, 66/255, 150/255}, icon = "icon\_music", }, { title = "Division", colour = {35/255, 119/255, 186/255}, icon = "icon\_games", }, } return M

Add a ‘sceneName’ field to each of your tables in table.lua matching the names of the lua files, then use this to call composer.gotoScene.

[lua]

composer.gotoScene(operations[category].sceneName, {effect=“slideLeft”, time=300, params={category=category}})

[/lua]

Nick it completely works like a charm on the sceneName variable. How can i assign it to “buttonTapped = function(event)” the other scene name? shall i create a new buttontapped function for it? 

Add a ‘sceneName’ field to each of your tables in table.lua matching the names of the lua files, then use this to call composer.gotoScene.

[lua]

composer.gotoScene(operations[category].sceneName, {effect=“slideLeft”, time=300, params={category=category}})

[/lua]

Nick it completely works like a charm on the sceneName variable. How can i assign it to “buttonTapped = function(event)” the other scene name? shall i create a new buttontapped function for it?