【问题标题】:Attempt to concatenate global 'sceneName' (a nil value) - Lua尝试连接全局'sceneName'(一个零值) - Lua
【发布时间】:2020-08-02 07:29:09
【问题描述】:

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

这是 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 本身没有场景,也没有 GUI。

标签: lua coronasdk


【解决方案1】:

尝试运行场景模板。尝试将作曲家要求添加到场景文件中的局部变量。

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

【讨论】:

    猜你喜欢
    • 2012-12-13
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    相关资源
    最近更新 更多