【问题标题】:main.lua: attempt to index upvalue 'bricks' (a function value)main.lua:尝试索引 upvalue 'bricks'(一个函数值)
【发布时间】:2017-04-22 00:33:37
【问题描述】:

从“主菜单”切换到游戏屏幕时出现此错误。点击“播放”,主菜单消失,出现1级。对于这个级别,我使用 displayGroup 添加了积木。 在 bricks:toFront(); 行出现错误如果我将此行/位置删除到其他地方,则在 bricks.insert(bricks, brick)

处出现错误
playButton:addEventListener("tap", loadGame);

function loadGame(event)
    if event.target.name  == "playbutton" then
        transition.to(menuScreenGrp, {time = 0, alpha = 0, onComplete = addGameScreen});
        playBtn:removeEventListener("tap", loadGame);
    end
end

function addGameScreen()
   -- code for displaying background and other stuff
   loadLevel1();
end

function loadLevel1()

    currentLevel = 1;
    bricks:toFront();  -- Got error here

    for row = 0, numOfRows - 1 do
    for column = 0, numOfColumns - 1 do

      --logic to position bricks
      physics.addBody(brick, "static", {density = 1, friction = 0, bounce = 0})
      bricks.insert(bricks, brick)

    end
  end
end

【问题讨论】:

    标签: android ios lua coronasdk


    【解决方案1】:

    快速找到解决方案。

    在参考文档中,组被初始化为局部变量:

    local bricks = display.newGroup();
    

    所以当我试图在函数内部访问它时,它给出了错误。

    解决方案是我刚刚声明了变量,然后在函数内部对其进行了初始化。

    【讨论】:

      猜你喜欢
      • 2019-10-10
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 2019-10-16
      • 1970-01-01
      • 2013-08-29
      相关资源
      最近更新 更多