help with buttons

Hey,

I have been trying to make buttons for a level selection using a while script…

  
local userdatafile = "save1" .. ".data"  
local curlvl = loadValue( userdatafile )  
  
local i = tonumber(curlvl)  
local x  
local lvl  
  
local onlevelBtn = function()  
  
 director:changeScene( "level" .. lvl)  
end  
  
while (i \> 0) do  
  
 levelBtn = ui.newButton{  
 defaultSrc = "levelbtn.png",  
 defaultX = 57,  
 defaultY = 57,  
 overSrc = "levelbtn-over.png",  
 overX = 57,  
 overY = 57,  
 onEvent = onlevelBtn,  
 id = "levelBtn",  
 text = i,  
 font = "",  
 textColor = { 0, 0, 0, 255 },  
 size = 16,  
 emboss = false,  
 }  
  
 x = 50 + i \* 60;  
  
 levelBtn.x = x levelBtn.y = 100  
 levelBtn.isVisible = true  
 i = i - 1  
end  

and I was wondering how I could get the information of what button is being pressed as the variable “lvl” so that if the button with the text 1 is pressed then “lvl” will be equal to 1 so it loads level1.

Thnx,
ultrasnofire [import]uid: 31078 topic_id: 27074 reply_id: 327074[/import]

anyone got an idea of how to do this? [import]uid: 31078 topic_id: 27074 reply_id: 110080[/import]