Why Dosen't My Function Get Called

I want to programatically setup a certain number of buttons by rows and columns. The following code shows the buttons on the screen, button when I press them, the function btnPress is not called. Any ideas would be greatly appreciated. (I’m using the ui.lua from the Ghosts and Monsters sample code.)

local ui = require("ui")display.setStatusBar(display.HiddenStatusBar) local mainscreen = function( ) local background = display.newImage( "black.png") local wd = display.contentWidth local ht = display.contentHeight background.x = wd / 2 background.y = ht / 2 local btns = {} local row = 1 local col = 1 local img_fle = "level.png" local btn_nme for i = 1, 20 do btns[i] = ui.newButton { defaultSrc = img_fle, defaultX = 60, defaultY = 60, onEvent = btnPress, id = i, align = "center", text = i, size = 12, emboss=true } btns[i].x = wd / 6 * col btns[i].y = ht / 5 * row if col == 5 then col = 1 row = row + 1 else col = col + 1 end local img_fle = "level.png" endendlocal btnPress = function( event ) print("Button Pressed" .. event.id )endmainscreen() [import]uid: 13201 topic_id: 5961 reply_id: 305961[/import]

Use the blockcode tags, it’s hard to read otherwise… [import]uid: 9371 topic_id: 5961 reply_id: 20454[/import]

You have to define the function before using it. There are a couple approaches to doing that; the simplest in this situation is simply cut and paste it to the top.

ADDITION: yeah what he said. The tags supported by this forum are listed between the box to type in and the button to post. [import]uid: 12108 topic_id: 5961 reply_id: 20455[/import]

Thanks.

I tried to update my original post but I got stuck because it would not let me choose the correct forum; only General and Corona SDK were available.
[import]uid: 13201 topic_id: 5961 reply_id: 20457[/import]