1
目前正在使用Corona模擬器開發我的第一款移動應用程序。我試圖讓我的一個按鈕去另一個場景,它會顯示另一個頁面。目前,這是我我的onRelease呼叫有問題嗎?
------------------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
電話?
任何人都可以向我解釋這是什麼意思或如何解決這個問題?
你好,謝謝你的反應不幸的是我已經把它改爲 onRelease = returnMonth 現在我得到這個錯誤 states.lua6:試圖索引全球的「自我」(一個零值) 棧回溯: [C]:在函數'error'中 ?:在函數'gotoScene'中 MainScreen.lua:8:在函數中'_onRelease' ?:in function'?' ?:功能 ?:在功能 我是否也必須在新的場景上有作曲家專欄? – ratman