The intended behavior is to fade the sprite to invisible over 3 seconds, and then deleting the game object. However, the actual behavior is the following (strange) output:
ERROR:SCRIPT: go.delete invoked with too many argumengs
stack traceback:
[C]: at 0x7ff78758b1b0
It also does not delete the game object.
Of course, a local method (containing nothing more than go.delete() in its body) can just be created and call-backed to delete the object, so the severity is not particularly great, but the engine loses some adult points by just yelling too many argumengs when it faces this particular issue.
The thing is that the callback function of go.animate() will be called with self, url, property as arguments. go.delete() expects two arguments, id and recursive. So when you pass in go.delete() it will get called like this go.delete(self, URL, property) which is obviously wrong…
I have a question related to this… I want to delete a gameobject after it is created in a factory.
I dont want to use an attached script… I have so many scripts that they are affecting performance.
Hence I am trying to use go.animate with a delete function…
I was trying this…
e.g
local b = factory.create(component, p,nil,nil,scale)
go.animate(b, "position.x", go.PLAYBACK_ONCE_FORWARD, p.x, go.EASING_LINEAR, 0.6, 0 ,function() go.delete(b) end)
Also tried it like this…
local b = factory.create(component, p,nil,nil,scale)
local url = msg.url(b)
go.animate(b, "position.x", go.PLAYBACK_ONCE_FORWARD, p.x, go.EASING_LINEAR, 0.6, 0 ,function() go.delete(url) end)
Thanks for the response… doesnt seem to work in my explosion function
function singleExplode(p)
p.z = EXPLOSION_LAYER
local component = "/createExplosions#explodedFactory"
local scale = 0.6 + 0.3 * math.random()
local b = factory.create(component, p,nil,nil,scale)
timer.delay(1, false, function() go.delete(b)end)
end
Are your saying the game object isn’t deleted? And how do you know that? Can you still see it? Is it perhaps a particle effect? The effect stays even if the game object is deleted.
Yes its just a simple atlas with 6 frames.
I put that function in a new project with the assets and it works fine… just in the main project the timer does not get called… I tried with a print statement… seems like a deeper bug in my code.
The singleExplode function is global. Could that be a problem? Perhaps not the function you think is being called? Do you have any errors in the console? Put a print() statement or perhaps a breakpoint and use the debugger?