Assign id to a physics.body

Hi there,

After a few months of feeling a little intimidated by codea, I’ve decided to gather some courage and tackle a little project.

Right now, I’m blocked at a little problem. I’m creating circles upon touches, no problem so far, an example shows exactly that. I’m now trying to do things with these individual circles, but I can’t figure out how to call them.

So here’s my first question: where and how to assign an Id to each individual object, so I can later do stuff with them? Somewhere there: circle = physics.body(CIRCLE, r) ?

Cheers!

You already did it. circle = physics.body(CIRCLE, r). Just use circle. to access it.

If you’re dealing with many circles, toss them circles into a table:

circles = {}
circle = physics.body(CIRCLE, r)
table.insert(circles, circle)

--then to access them you can use a for loop
for i,v in pairs(circles) do
    do stuff to circle using v as the circle and i as its index in the circles table
end

Oh of course! As often, it’s not technical difficulties or lack of knowledge that gets in the way, but rather poor imagination. Thank you so much! :slight_smile:

then you need to draw a circle over the physics body (because physics bodies are not visible), like

ellipse(circle.x,circle.y,r)