我如何修复这个错误?(Corona SDK)

所以,我从这段代码中得到了这个错误,我想知道我该怎么做才能让它工作。错误消息说“ERROR:表格期望。如果这是函数调用,则您可能使用了“。”而不是“:””我仍在学习Lua,所以这对我来说非常困惑,如果您能提供答案,我会非常感激。

function scene:create( event )
--声明变量
local sceneGroup = self.view
local background = display.newImage( "game_background.jpg", display.contentWidth, display.contentHeight )
    background.anchorX = 0
    background.anchorY = 0
    background.x, background.y = 0, 0
--对象“篮子”的旋转函数
local function rotateBasket(event)
    --旋转函数内声明的变量
    local t = event.target
    local phase = event.phase
    local basket = display.newImageRect("basket.jpg" , 90, 60)
    basket.x = display.contentCenterX
    basket.y = display.contentCenterY
    --旋转
    if (phase == "began") then
        display.getCurrentStage():setFocus( t )
        t.isFocus = true
        t.x1 = event.x
        t.y1 = event.y
    elseif t.isFocus then
        if (phase == "moved") then
            t.x2 = event.x
            t.y2 = event.y
            angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
            angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
            rotationAmt = angle1 - angle2
            t.rotation = t.rotation - rotationAmt
            t.x1 = t.x2
            t.y1 = t.y2
        elseif (phase == "ended") then
            display.getCurrentStage():setFocus( nil )
            t.isFocus = false
        end
    end
    --事件监听器
    basket:addEventListener("touch", rotateBasket)
    return true
end
--场景组插入
sceneGroup:insert( background )
sceneGroup:insert( basket )
end
点赞
用户3098020
用户3098020

我认为你声名 'basket' 对象的方式有点错。你是在 'rotateBasket' 函数内声名的 basket,这会使得此 'basket' 在函数外无法访问。我假设你是要声名一个背景和一个要旋转的 'basket' 图像。假设你的 rotateBasket 函数是正确的,你可以尝试以下代码:

--Rotation Function for Object "Basket"
local function rotateBasket(event)
    --Declared Variables inside rotation function
    local t = event.target
    local phase = event.phase

    --Rotation
    if (phase == "began") then
        display.getCurrentStage():setFocus( t )
        t.isFocus = true
        t.x1 = event.x
        t.y1 = event.y
    elseif t.isFocus then
        if (phase == "moved") then
            t.x2 = event.x
            t.y2 = event.y
            angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
            angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
            rotationAmt = angle1 - angle2
            t.rotation = t.rotation - rotationAmt
            t.x1 = t.x2
            t.y1 = t.y2
        elseif (phase == "ended") then
            display.getCurrentStage():setFocus( nil )
            t.isFocus = false
        end
    end
    return true
end

function scene:create( event )
    --Declared variables
    local sceneGroup = self.view

    --Create background
    local background = display.newImage( "game_background.jpg", display.contentWidth, display.contentHeight )
    background.anchorX = 0
    background.anchorY = 0
    background.x, background.y = 0, 0

    --Create basket
    local basket = display.newImageRect("basket.jpg" , 90, 60)
    basket.x = display.contentCenterX
    basket.y = display.contentCenterY

    --Add event listener to basket (may also be done in scene:show function)
    basket:addEventListener("touch", rotateBasket)

    --sceneGroup insertions
    sceneGroup:insert( background )
    sceneGroup:insert( basket )
end
2015-01-20 07:09:09
用户2653067
用户2653067

在函数内部声明了局部变量 basket 并试图将其插入到函数外的 scenegroup 中,但由于是局部变量,不能从函数外部访问。

-- 旋转对象“篮子”的功能函数
local function rotateBasket(event)
  -- 在旋转函数内声明变量
  local t = event.target
  local phase = event.phase
  local basket = display.newImageRect("basket.jpg" , 90, 60)
  basket.x = display.contentCenterX
  basket.y = display.contentCenterY

  -- 旋转
  if (phase == "began") then
    display.getCurrentStage():setFocus( t )
    t.isFocus = true
    t.x1 = event.x
    t.y1 = event.y
  elseif t.isFocus then
    if (phase == "moved") then
      t.x2 = event.x
      t.y2 = event.y
      angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
      angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
      rotationAmt = angle1 - angle2
      t.rotation = t.rotation - rotationAmt
      t.x1 = t.x2
      t.y1 = t.y2
    elseif (phase == "ended") then
      display.getCurrentStage():setFocus( nil )
      t.isFocus = false
    end
  end

  -- 将篮子插入到 scenegroup 中
  sceneGroup:insert( basket )

  -- 事件监听器
  basket:addEventListener("touch", rotateBasket)
  return true
end

-- 在 scenegroup 中插入 background
sceneGroup:insert( background )
2015-01-30 11:43:51