I'm new to Lua/Corona and need some assistance. Can someone explain why code snippit 1 but not code snippit 2 generates the following error:
main.lua:21: attempt to index global 'myButton' (a nil value)
--Code snippit 1
local button = {myButton,"button1.png",80,190}
-- Format of the table above is button name, image filename, x coordinate, y coordinate
---[[
for i = 1,1 do
b=button[i]
f=button[i+1]
x=button[i+2]
y=button[i+3]
b = display.newImage(f)
b.x=x
b.y=y
end
--]]
--[[
local myButton =
display.newImage( "button1.png" )
myButton.x = 80
myButton.y = 190
--]]
function myButton:tap(event)
p=p+1
return true
end
myButton:addEventListener("tap",myButton)
-----------------------------------
--Code snippit 2
local button = {myButton,"button1.png",80,190}
-- Format of the table above is button name, image filename, x coordinate, y coordinate
--[[
for i = 1,1 do
b=button[i]
f=button[i+1]
x=button[i+2]
y=button[i+3]
b = display.newImage(f)
b.x=x
b.y=y
end
--]]
---[[
local myButton = display.newImage( "button1.png" )
myButton.x = 80
myButton.y = 190
--]]
function myButton:tap(event)
p=p+1
return true
end
myButton:addEventListener("tap",myButton)