.lua:1051: bad argument #-2 to 'insert' (Proxy expected, got nil)

Can you tell me in a basic bullet list of steps what you are trying to do?

It looks like you have an object and you want to add a particle emitter to it, then delete that emitter after 500 ms.  Is that right?

self is an object group containing a weapon bullet image object.

I then create a smoke trail emitter for the bullet with self.bulletTrailEffect

I want to delete the emitter (and everything else bullet related) after 500ms

This would work better:

local function addTrail( obj ) if( obj == nil ) then error("Object is nil") end local emitter = display.newEmitter( ... ) -- fill is your own settings here if( emitter == nil ) then error("Emitter is nil") end -- parent is group obj is in. obj.parent:insert( emitter ) -- No need to track this or cancel it is safe to run even if obj is removed before -- it is called. timer.performWithDelay( 500, function() display.remove( emitter ) display.remove( obj ) end ) end -- later ... local tmp = display.newCircle( 10, 10, 10 ) addTrail( tmp ) 

Note: This doesn’t include code to make the emitter follow the object if it moves.

This would have the emitter follow the object
 

local function addTrail( obj ) if( obj == nil ) then error("Object is nil") end local emitter = display.newEmitter( ... ) -- fill is your own settings here if( emitter == nil ) then error("Emitter is nil") end -- parent is group obj is in. obj.parent:insert( emitter ) function emitter.enterFrame( self ) if( type(self.removeSelf) ~= "function" ) then Runtime:removeEventListener( "enterFrame", self return elseif( not obj.removeSelf or type(obj.removeSelf) ~= "function" ) then Runtime:removeEventListener( "enterFrame", self return end self.x = obj.x self.y = obj.y end Runtime:addEventListener( "enterFrame", emitter ) -- No need to track this or cancel it is safe to run even if obj is removed before -- it is called. timer.performWithDelay( 500, function() Runtime:removeEventListener( "enterFrame", emitter ) display.remove( emitter ) display.remove( obj ) end ) end -- later ... local tmp = display.newCircle( 10, 10, 10 ) addTrail( tmp )

Thank you for your fast and detailed help roaminggamer!

I wish you a Merry Christmas!

You’re welcome.

Ping back later if there is a problem with this solution. Remember, I don’t run these I just type them, so the ‘brain compiler’ may be faulty.

-Ed

I will rework my code after Christmas based on your code sample.

One more thing: can you please explain why the above newGroup code is wrong in the sample above?

It isn’t 100% wrong, but I wouldn’t feel good encouraging you to continue using the table returned by a timer that way.

I would treat the table returned by performWithDelay() with caution and not as a generic table. (Others may not agree).

The real issue I see is that the variable hierarchy is too deep for the purpose it is serving. You can greatly simplify adding, tracking, and removing emitters.

At the end of the day I suspect either the object you are adding the emitter to is not getting created, OR the emitter is not thus the failed insert.

Great info regarding this. Thank you very much!