我对nil变量有疑问。因为我是lua的初学者,所以这经常发生在我身上。这是我收到的错误消息:

attempt to index global 'popUp_circle' (a nil value) stack traceback

我正在使用的代码:
function popUp(header, text)
    local popUp_overlay = display.newImageRect("images/transparent_black.png", 480, 320)
        popUp_overlay.x = halfW
        popUp_overlay.y = halfH
        popUp_overlay.alpha = 0.3
        group:insert(popUp_overlay)

    local popUp_background = display.newImageRect("images/popUp.png", 300, 150)
        popUp_background.x = halfW
        popUp_background.y = halfH
        group:insert(popUp_background)

    local popUp_header = display.newText(header,0,0,native.systemFont,14)
        popUp_header.x = halfW+5
        popUp_header.y = halfH-47
        group:insert(popUp_header)

    local popUp_text = display.newText(text,0,0,native.systemFont,14)
        popUp_text.x = halfW
        popUp_text.y = halfH+10
        group:insert(popUp_text)

    local popUp_circle = display.newCircle( halfW+135, halfH-55, 8 )
        popUp_circle:setFillColor( 0 )
        popUp_circle.alpha = 0.3
        group:insert(popUp_circle)
        timer.performWithDelay( 100, timerCircle )
end

function onClickCircle()

end

function timerCircle()
    popUp_circle:addEventListener( "tap", onClickCircle )
end

最佳答案

popUp_circlepopUp中定义为本地,因此在timerCircle中看不到。

07-26 06:15