Problem with menu display.new text

okay, so I have made a menu system

I use a for loop to create the menu, but I can’t seem to access any of the items in the menu except the last one that was displayed. for example here’s a picture of the menu.

http://screencast.com/t/Gt3qeWX8

and in there i have this

[lua]

function objTap()

    local r = math.random(0,255)

    local g = math.random(0,255)

    local b = math.random(0,255)

    menuDisp:setFillColor(r/255, g/255, b/255)

    end

display.currentStage:addEventListener( “tap”, objTap )

[/lua]

and I made the menu by doing this

[lua]

    menuData = {“Option 1”, “Option 2”, “Option 3”, “Option 4”, “Option 5”}

for i = 1, #menuData do

    menuDisp = display.newText(menuData[i], _w/2, initY + (i-1) * 50, “Arial”, 45)

    end

[/lua]

any help would be appreciated.

I just want to be able to make each option do something different when it is tapped.

your using same variable to create different display objects, that’s why you can only access the last one.

try:

local menuDisp={} for i = 1, #menuData do menuDisp[i] = display.newText(menuData[i], \_w/2, initY + (i-1) \* 50, "Arial", 45) end

to access the object you use: menuDisp[number]

your using same variable to create different display objects, that’s why you can only access the last one.

try:

local menuDisp={} for i = 1, #menuData do menuDisp[i] = display.newText(menuData[i], \_w/2, initY + (i-1) \* 50, "Arial", 45) end

to access the object you use: menuDisp[number]