目前正在使用Corona模拟器开发我的第一个移动应用程序。我试图让我的一个按钮去另一个场景,它将显示另一个页面。目前这就是我所拥有的
------------------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
问题
我很难弄清楚为什么我从电晕模拟器中收到此错误:
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>
我的onRelease
电话有问题吗?
任何人都可以向我解释这意味着什么或我如何解决这个问题?
答案 0 :(得分:2)
是。问题是这一行
onRelease = returnMonth()
该行将调用returnMonth()方法,并将结果放入调用表的onRelease参数中widget.newButton
。我不能从这里测试它,但我很确定你应该删除括号:
onRelease = returnMonth
编辑:此外,storyboard:gotoScene(...)
- 它显然需要自我参数,并使用冒号而不是点将只提供它。