referring to physics particle by name?

Hello forum, Particle Candy new-be here.

I created an emitter, attached it to a target and get it triggered and sending out particles which are physics particles. so far so good.

My problem now is how to refer to the individual particles so I can trigger events on collision.
In the .PhysicsProperties I assign a name. When I use that name, I get an error saying that name was a nil value.

A very *simple* example of how to use that name, just containing the essential elements, would be very helpful.
(The provided examples are all very, very impressive, but also complex and demonstrating several things at once. I found only one so far using the physics properties and there the name gets assigned but is not used for anything it seems…) [import]uid: 109677 topic_id: 21737 reply_id: 321737[/import]

Post the code your using and maybe we can help, if its getting a nil value, then the object the name is attached to is either niled out or not created yet, or in the process of being nilled at the time that you are trying to reference it. [import]uid: 126161 topic_id: 21737 reply_id: 86335[/import]

the code is as follows:

–CREATE AN EMITTER
Particles.CreateEmitter(“p_Em”, tO.x, tO.y, tO.rotation, true, false, false)
Particles.SetEmitterTarget(“p_Em”, tO, true, 0, 0, 0)

– DEFINE PARTICLE TYPE PROPERTIES
lop_ Properties = {}
Properties.imagePath = “pImage.png”
Properties.imageWidth = 45 – PARTICLE IMAGE WIDTH (newImageRect)
Properties.imageHeight = 16 – PARTICLE IMAGE HEIGHT (newImageRect)
Properties.rotationStart = -90
Properties.velocityStart = 940 – PIXELS PER SECOND
–Properties.killOutsideScreen = true – PARENT LAYER MUST NOT BE NESTED OR ROTATED!
Properties.lifeTime = 1000 – MAX. LIFETIME OF A PARTICLE
– APPLY PHYSICS:
Properties.PhysicsMaterial = {density = 0.05, friction = 0.0, bounce = 0.0}
Properties.PhysicsProperties = {isFixedRotation = false, name = “pEmInstance”}

– CREATE THE ACTUAL PARTICLE TYPE
Particles.CreateParticleType (“p_EmParticleType”, Properties)

– WE DON’T NEED THIS ANYMORE
–Properties = nil

–FEED THE EMITTER
Particles.AttachParticleType(“p_Em”, “p_EmParticleType”, 1, 1000, 0)

–then:
lop_ p_EmEmitter = Particles.GetEmitter(“p_Em”)
Particles.StartEmitter(“p_Em”, true) [import]uid: 109677 topic_id: 21737 reply_id: 86336[/import]

and I am only trying to access that name if MaxParticles() > 0. [import]uid: 109677 topic_id: 21737 reply_id: 86388[/import]

if you are trying to trigger events on collision
you can try something like

[lua]function collision( event )
if event.other.name == “pEmInstance” then
– enter
– code
– here
end
end[/lua] [import]uid: 114118 topic_id: 21737 reply_id: 86412[/import]

this is what I do with my other elements, but pEMINstance is nil whenever I try to access it.

I guess that indicates I am not actually accessing the “right” pEMINstance, hence my question how to refer to these names created. [import]uid: 109677 topic_id: 21737 reply_id: 86440[/import]

I got the collision event to work, but I am not using the name I assign in the properties, and I am not sure the way I am doing this is most efficient, so still an example that deals with that would be much appreciated. [import]uid: 109677 topic_id: 21737 reply_id: 86452[/import]

“My problem now is how to refer to the individual particles so I can trigger events on collision.”

Did you check out the included sample “Sample Physics Particles” yet? It shows how to detect physics collision and also how to determine WHAT objects collided. Just run it and note the console output.

As you can see in the sample code, there is a listener function (“onCollision”) called when objects collide. This function receives an event object that contains two table fields (“object1”, “object2”) which you can use to access both colliding objects.

For more information on physics and collision detection please also refer to the Corona SDK physics reference.
[import]uid: 10504 topic_id: 21737 reply_id: 87259[/import]