试图连接全局'sceneName'(nil值)-Lua

问题描述 投票:0回答:1

我实际上复制并粘贴了此代码,它对我的​​朋友有用。

这是main.lua的代码


composer = require( "composer" )

composer.gotoScene("mainMenu")  

在同一目录中,我有一个名为“ mainMenu”的文件,这是代码:

local scene = composer.newScene()

function scene:show(event)
  -------------
end


scene:addEventListener( "show", scene )
return scene

当我运行该应用程序时,出现错误“尝试连接全局'sceneName'(nil值)”]

lua coronasdk
1个回答
0
投票

尝试运行场景模板。尝试要求作曲家使用场景文件中的局部变量。

https://docs.coronalabs.com/api/library/composer/index.html#scene-template

local composer = require( "composer" )

local scene = composer.newScene()

-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------




-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------

-- create()
function scene:create( event )

    local sceneGroup = self.view
    -- Code here runs when the scene is first created but has not yet appeared on screen

end


-- show()
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)

    elseif ( phase == "did" ) then
        -- Code here runs when the scene is entirely on screen

    end
end


-- hide()
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Code here runs when the scene is on screen (but is about to go off screen)

    elseif ( phase == "did" ) then
        -- Code here runs immediately after the scene goes entirely off screen

    end
end


-- destroy()
function scene:destroy( event )

    local sceneGroup = self.view
    -- Code here runs prior to the removal of scene's view

end


-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------

return scene
© www.soinside.com 2019 - 2024. All rights reserved.