How can I print physics objects properties to terminal for debug purposes?

Hello

I am new to Corona and Lua in general and I am having some problems which I am sure I could fix if I could just print some data to the terminal for debug purposes.

I need to be able to print the physical properties which are set in the physics.addBody() function. For example I need to print the friction, bounce and density properties to the terminal.

My reason being that in my game when the player “dies” I restart the game using Storyboard etc, but at some point I believe these physics properties change/do not initialise, resulting in the character movement being completely different than it was in the first round.

I tried the code below but its just printing “nil” every time :frowning:

print(mainFloor.bounce)

print(mainFloor.friction)

print(mainFloor.density)

Any help would be appreciated :slight_smile:

Thanks guys

I’m not sure if those properties are readable, so what I would do is add my own custom properties to the object at the same time as adding the physics body.  

e.g.

local myObject = display.new...... physics.addBody(myObject, {friction = 1, density = 5, etc...}) myObject.friction = 1 myObject.density = 5

Then you should be able to print those properties out.  

You will have to make sure that you set them everywhere that add a physics body to the object (if you do this in multiple parts of your code)…

I’m not sure if those properties are readable, so what I would do is add my own custom properties to the object at the same time as adding the physics body.  

e.g.

local myObject = display.new...... physics.addBody(myObject, {friction = 1, density = 5, etc...}) myObject.friction = 1 myObject.density = 5

Then you should be able to print those properties out.  

You will have to make sure that you set them everywhere that add a physics body to the object (if you do this in multiple parts of your code)…