WeeD1 Posted January 25, 2019 Posted January 25, 2019 oi, alguém poderia me ajudar com um WARNING em um script? WARNING: ExplodeSome\dvoe_s.lua:4: Bad argument @ 'destroyElement' [Expected element at argument 1] local timer = 500 function desaparecer() setTimer(destroyElement, timer, 1, source) end addEventHandler("onVehicleExplode", getRootElement(), desaparecer)
Blaack Posted January 25, 2019 Posted January 25, 2019 Creio que ai não está definindo quem é o elemento source. Tenta ai : (Nao testado) local timer = 500 function desaparecer() if getElementType(source) == "vehicle" then setTimer(destroyElement, timer, 1, source) end end addEventHandler("onVehicleExplode",getRootElement(), desaparecer) 1
WeeD1 Posted January 25, 2019 Author Posted January 25, 2019 (edited) Ele ainda acusa o mesmo erro Edited January 25, 2019 by WeeD1
Other Languages Moderators Lord Henry Posted January 25, 2019 Other Languages Moderators Posted January 25, 2019 Isso acontece pois dentro do timer o source deixa de existir. Pois ele pertence ao evento da função principal somente. Coloque o source dentro de uma variável local, dai dentro do timer vc verifica se o elemento desta variável ainda existe antes de tentar destruí-lo. local timer = 500 -- Meio segundo. function desaparecer () local theVehicle = source -- theVehicle = o elemento que explodiu. setTimer (function () -- Inicia o timer. if isElement (theVehicle) then -- Se o elemento que está na variável ainda existe, então: destroyElement (theVehicle) -- Destrói o veículo. theVehicle = nil -- Anula essa variável, que não será mais usada. end end, timer, 1) end addEventHandler ("onVehicleExplode", getRootElement(), desaparecer) 1
WeeD1 Posted January 25, 2019 Author Posted January 25, 2019 12 minutes ago, Lord Henry said: Isso acontece pois dentro do timer o source deixa de existir. Pois ele pertence ao evento da função principal somente. Coloque o source dentro de uma variável local, dai dentro do timer vc verifica se o elemento desta variável ainda existe antes de tentar destruí-lo. local timer = 500 -- Meio segundo. function desaparecer () local theVehicle = source -- theVehicle = o elemento que explodiu. setTimer (function () -- Inicia o timer. if isElement (theVehicle) then -- Se o elemento que está na variável ainda existe, então: destroyElement (theVehicle) -- Destrói o veículo. theVehicle = nil -- Anula essa variável, que não será mais usada. end end, timer, 1) end addEventHandler ("onVehicleExplode", getRootElement(), desaparecer) Obrigado! Deu certo aqui.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now