Proxy “什么是?”;错误参数#-1到';新线';(预期代理,为零)平均值

Proxy “什么是?”;错误参数#-1到';新线';(预期代理,为零)平均值,proxy,lua,coronasdk,Proxy,Lua,Coronasdk,我一直在做一个游戏。游戏包括(一部分)获取触摸事件的x和y位置,在触摸事件移动时跟踪它,并将x/y值添加到表中。我已经把它记下来了。但是,当我尝试从表中创建一行时,会出现以下错误: /Users/jordanmcbride/Desktop/Programing/Lua Projects/When Balls Drop/main.lua:21: bad argument #-1 to 'newLine' (Proxy expected, got nil) stack traceback:

我一直在做一个游戏。游戏包括(一部分)获取触摸事件的x和y位置,在触摸事件移动时跟踪它,并将x/y值添加到表中。我已经把它记下来了。但是,当我尝试从表中创建一行时,会出现以下错误:

/Users/jordanmcbride/Desktop/Programing/Lua Projects/When Balls Drop/main.lua:21: bad argument #-1 to 'newLine' (Proxy expected, got nil)
stack traceback:
    [C]: in function 'newLine'
    /Users/jordanmcbride/Desktop/Programing/Lua Projects/When Balls Drop/main.lua:21: in function </Users/jordanmcbride/Desktop/Programing/Lua Projects/When Balls Drop/main.lua:8>
    ?: in function <?:221>
以下是我的全部代码:

    -- Hides the status bar at the top of the screen
display.setStatusBar(display.HiddenStatusBar)

print("App Starting!")

linePositions = {}

function drawLineTouchListener( event )

    if event.phase == "began" then
        currx = event.x
        curry = event.y
        table.insert( linePositions, currx)
        table.insert( linePositions, curry)
    elseif event.phase == "moved" then
        currx = event.x
        curry = event.y
        table.insert( linePositions, currx)
        table.insert( linePositions, curry)
    elseif event.phase == "ended" then
        line = display.newLine( linePositions )
        test = {
        0, 0,
        20, 20,
        40, 40, 
        60, 60, 
        80, 80}

        line2 = display.newLine( test)
        line2:setStrokeColor( black )
    end


    print( "x: "..currx.."  y:"..curry)

end

function playButtonTouch ( event )

    if ( event.phase == "ended" ) then

    end
end

function highScoreButtonTouch ( event )

    if ( event.phase == "ended" ) then

    end
end

function quitButtonTouch ( event )

    if ( event.phase == "ended" ) then
        os.exit(0)
    end
end


function displayMenu ()
    mainMenuGroup = display.newGroup()

    title = display.newImage(mainMenuGroup, "Title.png", display.contentCenterX, 20) 
    title:scale( .3, .3 )

    playButton = display.newImage(mainMenuGroup, "Play Button.png", display.contentCenterX, display.contentHeight - 300)
    playButton:scale( .3, .3 )

    quitButton = display.newImage(mainMenuGroup, "Quit Button.png", display.contentCenterX, display.contentHeight - 200)
    quitButton:scale( .3, .3 )

    highScoreButton = display.newImage(mainMenuGroup, "Highscore Button.png", display.contentCenterX, display.contentHeight - 100)
    highScoreButton:scale( .3, .3 )

    playButton:addEventListener( "touch", playButtonTouch )

    quitButton:addEventListener( "touch", quitButtonTouch )

    highScoreButton:addEventListener( "touch", highScoreButtonTouch )
end


--Creates a solid white background that doubles for a touch listner
background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight+100)
background:setFillColor(1, 1, 1 )

background:addEventListener( "touch", drawLineTouchListener )

displayMenu()

您的问题源于这样一个事实:当函数需要单个参数时,您正在传递一个表

相反,使用
unpack(linePositions)
将“解包”表中的所有内容(通过将其作为元组返回)


请注意在Lua5.2及更高版本中,它是table.unpack。

您看过文档了吗?@greatwolf是的,我从中得到的只是如何创建一条带有预定义点的线。例如:本地myLine=display.newLine(0,010010)。而且你不能点击它们…试着
解包(行位置)
并将其传递给
显示。newLine
@greatwolf工作起来很有魅力。非常感谢。(您应该将其添加到解决方案中,并进行一些解释):)
    -- Hides the status bar at the top of the screen
display.setStatusBar(display.HiddenStatusBar)

print("App Starting!")

linePositions = {}

function drawLineTouchListener( event )

    if event.phase == "began" then
        currx = event.x
        curry = event.y
        table.insert( linePositions, currx)
        table.insert( linePositions, curry)
    elseif event.phase == "moved" then
        currx = event.x
        curry = event.y
        table.insert( linePositions, currx)
        table.insert( linePositions, curry)
    elseif event.phase == "ended" then
        line = display.newLine( linePositions )
        test = {
        0, 0,
        20, 20,
        40, 40, 
        60, 60, 
        80, 80}

        line2 = display.newLine( test)
        line2:setStrokeColor( black )
    end


    print( "x: "..currx.."  y:"..curry)

end

function playButtonTouch ( event )

    if ( event.phase == "ended" ) then

    end
end

function highScoreButtonTouch ( event )

    if ( event.phase == "ended" ) then

    end
end

function quitButtonTouch ( event )

    if ( event.phase == "ended" ) then
        os.exit(0)
    end
end


function displayMenu ()
    mainMenuGroup = display.newGroup()

    title = display.newImage(mainMenuGroup, "Title.png", display.contentCenterX, 20) 
    title:scale( .3, .3 )

    playButton = display.newImage(mainMenuGroup, "Play Button.png", display.contentCenterX, display.contentHeight - 300)
    playButton:scale( .3, .3 )

    quitButton = display.newImage(mainMenuGroup, "Quit Button.png", display.contentCenterX, display.contentHeight - 200)
    quitButton:scale( .3, .3 )

    highScoreButton = display.newImage(mainMenuGroup, "Highscore Button.png", display.contentCenterX, display.contentHeight - 100)
    highScoreButton:scale( .3, .3 )

    playButton:addEventListener( "touch", playButtonTouch )

    quitButton:addEventListener( "touch", quitButtonTouch )

    highScoreButton:addEventListener( "touch", highScoreButtonTouch )
end


--Creates a solid white background that doubles for a touch listner
background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight+100)
background:setFillColor(1, 1, 1 )

background:addEventListener( "touch", drawLineTouchListener )

displayMenu()