addbody error when used in a conditional statement

Putting addbody within a condition statement produces an error:

if xxx == yyy then
physics.addBody(image3, {density=1.0, friction=0.3, bounce=0.6} )
end

Runtime error
…K2E+++TI/-Tmp-/TemporaryItems/525/scene05_Game01.lua:468: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘addBody’ [import]uid: 6288 topic_id: 19871 reply_id: 319871[/import]

Hey there - can you run this plug and play code and let me know if you are getting the error, please?

[lua]display.setStatusBar(display.HiddenStatusBar)

require ( “physics” )
physics.start()
physics.setGravity( 0, 7 )

myObj = display.newCircle( 100, 100, 25 )

local a = true

local function test ()
if a == true then
physics.addBody(myObj)
end
end
test()[/lua]

If so, what version of Corona are you using?

If not - double check that the object you are referring to exists and is accessible from the function.

Peach :slight_smile: [import]uid: 52491 topic_id: 19871 reply_id: 77215[/import]

Thanks Peach: I’m at version 715. The plug and play code works just fine. If I remove the conditional statements in my program, the addbody code runs just fine. The image does exist. However, fyi the image is based on table. image = display.newImage( imgTable[1][“image”]. Keep in mind that everything works just fine until I use the addbody within a conditional statement. [import]uid: 6288 topic_id: 19871 reply_id: 77218[/import]

OK, just to clarify here, you CAN add the image as a physics body if you aren’t using a conditional statement?

If so please use this form;
http://developer.anscamobile.com/content/bug-submission

Thanks,
Peach :slight_smile: [import]uid: 52491 topic_id: 19871 reply_id: 77256[/import]

I have submitted this to the bug-submission group. I am using the Storyboard software. [import]uid: 6288 topic_id: 19871 reply_id: 77371[/import]