Check for aspects of physics bodies in tables.

say I want to print the y coordinate of a physics body that is the second latest physics body to be inserted into the “tab” table. the first thing that I would think to write is:

print(tab[#tab-1].y)

This for some reason does not work, however. Can someone please explain why it doesn’t work and how I may edit my syntax to make it work?
Also, how would I be able to print or change the physics body’s placement in the table without having to do so inside of a generic “for” loop for the table.

Ok that makes things much easier for me. I wish I knew this previously

table items aren’t always given a numeric index. You can force this to happen

--use this
tab[#tab+1]=my_body
--instead of
table.insert(tab,my_body)

--then you can say
print(tab[#tab-1].y)

or, if your body has a name, you can insert it in the table like this

--this
tab[body_name]=my_body

--then you can say
print(tab[body_name].y)