gpt4 book ai didi

android - 电晕 : Check nil value before call onComplete event

转载 作者:行者123 更新时间:2023-11-29 12:57:46 26 4
gpt4 key购买 nike

在调用 onComplete 之前,我需要检查“regalo”是否为 nil,因为有时会被 Collision 事件删除,当我调用 onComplete=removeRegalo 时它会返回错误 nil 值。

错误:尝试调用方法“removeSelf”(零值)

有什么想法吗?

    local function removeRegalo(event)
event:removeSelf()
event = nil
end
local function tiraregalo()
regalo = display.newImageRect("images/regalo.png", 30, 30)
regalo.x = ship.x
regalo.y = ship.y
regalo:toFront()
regalo.name = "regalo"
physics.addBody( regalo, {isSensor = true } )
grupoCasas:insert(regalo)
local wind = 10
transition.to(regalo,{time=1500, y = screenH + 30, x = regalo.x + wind,rotation= math.random(-20,60), onComplete=removeRegalo})
end
function onCollision( event )
if(event.object1.name == "casa" and event.object2.name == "regalo") then
display.remove( event.object2 )
end
end

最佳答案

local function removeRegalo(event)
if event == nil then return end
event:removeSelf()
-- event = nil Not really needed, but okay if you want it here.
end

关于android - 电晕 : Check nil value before call onComplete event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20611225/

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