Currently working on my first mobile app using the Corona simulator. I am trying to get one of my buttons to go another scene where it will display another page. Currently this is what I have
------------------main.lua-----------------
display.setStatusBar( display.HiddenStatusBar )
local storyboard = require "storyboard"
storyboard.gotoScene( "MainScreen" )
------------------MainScreen.lua------------------------
local composer = require( "composer" )
local storyboard = require ("storyboard")
local widget = require "widget"
local scene = storyboard.newScene()
local function returnStates()
storyboard.gotoScene( "states", "crossFade", 1000 )
return true
end
local function returnMonth()
storyboard.gotoScene( "months", "crossFade", 1000 )
return true
end
----------------------------------------
function scene:createScene( event )
local group = self.view
local background = display.newImage( "blue.jpg" )
local logo = display.newImage("black.png")
logo.x=160
logo.y=100
local xor = display.newImage("or.png")
xor.x=145
xor.y=315
buttonHome = widget.newButton{
defaultFile = "statebutton.png",
overFile = "pressedstate.png",
onRelease = returnStates
}
buttonHome.x = 160
buttonHome.y = 230
buttonHome2 = widget.newButton{
defaultFile = "monthbutton.png",
overFile = "pressedmonth.png",
onRelease = returnMonth()
}
buttonHome2.x = 160
buttonHome2.y = 400
group:insert ( background )
group:insert ( buttonHome )
group:insert ( buttonHome2 )
end
function scene:enterScene( event )
local group = self.view
end
function scene:exitScene( event )
local group = self.view
end
function scene:destroyScene( event )
local group = self.view
if buttonHome then
buttonHome:removeSelf()
buttonHome = nil
end
if buttonHome2 then
buttonHome2:removeSelf()
buttonHome2 = nil
end
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
QUESTION
I am having a hard time figuring out why I am getting this error from my Corona Simulator:
states.lua:: attempt to index global 'self' (a nil value)
stack traceback:
[C]: in function 'error'
?: in function 'gotoScene'
MainScreen.lua:8: in function '_onRelease'
?: in function '?'
?: in function <?:677>
?: in function <?:221>
Is there something wrong with my onRelease
call?
Can anyone explain to me what this means or how I can fix this?
Yes. The problem is the line
This line will call the returnMonth() method and put the result in the onRelease argument of the call table to
widget.newButton
. I cannot test it from here, but I'm pretty sure you should remove the parenthesis:Edit: Also,
storyboard:gotoScene(...)
– it apparently needs the self argument, and using a colon instead of dot will give it just that.