gpt4 book ai didi

lua - 一个零值,尝试了一切

转载 作者:行者123 更新时间:2023-12-02 08:35:50 25 4
gpt4 key购买 nike

我对 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 中是看不到的。

关于lua - 一个零值,尝试了一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21631085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com