Lua / Corona尝试索引布尔值

时间:2013-11-30 15:26:26

标签: lua osx-mountain-lion corona

看起来我在从关卡选择页面转换到第一级时遇到问题。我想可能是因为我在1级失去了一些东西,但我不确切知道。

levelSelect.lua

module(..., package.seeall)

local director = require ("director")

local physics = require("physics")
physics.start()

local widget = require( "widget" )

-- Function to handle button events
local function handleButtonEventLevel1( event )
local phase = event.phase
if "ended" == phase then
    director:changeScene("lvl1")
    end
end

--local function goLevel1()
    --director:changeScene("lvl1")
    --return true
--end
--widget.newButton:addEventListener("tap", goLevel1)

local function handleButtonEventToPage( event )
    local phase = event.phase
    if "ended" == phase then
        director:changeScene("page")
    end
end

-- Main function - MUST return a display.newGroup()
function new()
    local localGroup = display.newGroup()

    local background = display.newImage("bigtestsky.png")
    background.x=150
    background.y=250

    local myButton = widget.newButton
    {
        left = 25,
        top = 25,
        width = 100,
        height = 50,
        defaultFile = "default.png",
        overFile = "over.png",
        label = "1",
        font = "LS",
        fontSize = 20,
        labelColor = { default = {0,0,50}, over = {0,0,255} },
        onEvent = handleButtonEventLevel1,
    }

    local myButton = widget.newButton
    {
        left = 25,
        top = 415,
        width = 100,
        height = 50,
        defaultFile = "default.png",
        overFile = "over.png",
        label = "BACK",
        font = "LS",
        fontSize = 20,
        labelColor = { default = {0,0,50}, over = {0,0,255} },
        onEvent = handleButtonEventToPage,
    }

    return localGroup
end

lvl1.lua

local physics = require("physics")
physics.start()
local widget = require( "widget" )

(这就是我在第一级缺少某些东西的意思。有人可以帮忙吗?)


stack traceback:
        [C]: ?
        .../myName/Desktop/Bubbles! App/director.lua:116: in function 'loadScene'
        .../myName/Desktop/Bubbles! App/director.lua:394: in function 'changeScene'
        ...myName/Desktop/Bubbles! App/levelSelect.lua:14: in function '_onEvent'
        ?: in function '?'
        ?: in function <?:405>
        ?: in function <?:218>

1 个答案:

答案 0 :(得分:0)

这是由于您的课程出现了一些问题:lvl1.lua

如果发生此类错误,请打开director.lua分析错误返回行。这将帮助您找到真正的问题。

在这里,您必须在lvl1.lua中写下更多行,如下所示:

module(...,package.seeall) -- If this line is not written, then the package will not be loaded.

function new()   -- Module 'lvl1' must have a new() function
local localGroup = display.newGroup() -- The scene should create a display group
    local physics = require("physics")
    physics.start()
    local widget = require( "widget" )
    print("Inside lvl1...")

return localGroup; -- And the scene should return the previously created display group.
end

保持编码..............:)