Corona SDK 的gotoScene错误。

我正在使用Corona SDK制作一个应用程序,当我点击试图加载我的第一关卡的按钮时,我遇到了一个错误。

以下是我的代码:

main.lua

local storyboard = require "storyboard"
storyboard.gotoScene("menu")

menu.lua

local storyboard = require ("storyboard")
local scene = storyboard.newScene()

function scene:createScene( event )

    local screenGroup = self.view

    -- 背景
    bg = display.newImage("images/bg.png")
    bg.x = display.contentCenterX
    bg.y = display.contentCenterY
    screenGroup:insert(bg)

    -- 标题
    title = display.newImage("images/title.png")
    title.x = display.contentCenterX
    title.y = display.contentCenterY - 100
    screenGroup:insert(title)

    -- 玩游戏
    play = display.newImage("images/playgame.png")
    play.x = display.contentCenterX - 170
    play.y = display.contentCenterY - 27
    screenGroup:insert(play)

    -- 关于我们
    about = display.newImage("images/about.png")
    about.x = display.contentCenterX - 100
    about.y = display.contentCenterY + 40
    screenGroup:insert(about)

    -- 关卡选择
    select = display.newImage("images/select.png")
    select.x = display.contentCenterX
    select.y = display.contentCenterY + 100
    screenGroup:insert(select)

end

function start(event)
    if event.phase == "began" then
        storyboard.gotoScene("level1", "fade", 400)
    end
end

function start2(event)
    if event.phase == "began" then
        storyboard.gotoScene("about", "fade", 400)
    end
end

function start3(event)
    if event.phase == "began" then
        storyboard.gotoScene("selectlvl", "fade", 400)
    end
end

function scene:enterScene(event)

    play:addEventListener("touch", start)
    about:addEventListener("touch", start2)
    select:addEventListener("touch", start3)

end

scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )

return scene

而我在level1.lua中没有任何代码

我得到的错误是:

运行时错误
    ?:0: attempt to concatenate global 'sceneName' (a nil value)
stack traceback:
    [C]: ?
    ?: in function 'gotoScene'
    ...s \ corona projects \ stickman障碍课程\ menu.lua.42: in function
<...s \ corona projects \ stickman障碍课程\ menu

感谢您的阅读,希望您能找到答案,因为我不能 :)

点赞
用户2753334
用户2753334

首先,检查你在 listener、level1、about 中是否拥有所有的 Lua 文件,并且文件名应该与大小写敏感性匹配。

你的 level1.lua 中有问题,它不应该有 'o' 代码。

如果你想要使用 0 代码来实现 storyboard,请确保你已经在顶部实现了 storyboard 对象,并且该场景已经从底部正确返回了。

像这样:

--Top
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

--Level1.lua 的最后一行

return scene
2014-01-21 07:32:26
用户7941332
用户7941332

mathew是正确的。跟随他的步骤。

我只是想添加一个未来的小贴士,你可能会发现有用。在调试错误代码时,如果代码状态显示global (a nil value),这意味着某些东西为空,也就是当没有物体时无法调用对象。函数中的?表示包含该空值的特定对象或函数。如果你再次看到这个错误,请检查是否有拼写错误。

2017-07-24 13:26:25