"Proxy expected, got nil"

Writing one of my first programs in Lua with the Corona SDK, and I’m getting the following error:
main.lua:10: bad argument #-2 to ‘addBody’ (Proxy expected, got nil)

Here’s my code. It’s probably just a stupid syntax error.

[code]local physics = require(“physics”)
physics.start()

local ground = display.newRect(160, 445, 160, 20)
ground:setFillColor(255, 255, 255)

local circle = display.newCircle(200, 150, 50)
circle:setFillColor(255, 0, 0)

physics:addBody(ground, “static”, {friction = 0.5, bounce = 0.3})
physics:addBody(circle, {density = 1.0, friction = 0.3, bounce = 0.2, radius = 50})[/code]

Thanks in advance. [import]uid: 30657 topic_id: 5769 reply_id: 305769[/import]

physics.addbody
When you have an opportunity like this, look at some code that works or compare your code to the API reference. : vs. . is Lua. Play with : and . until you know you know it. [import]uid: 12635 topic_id: 5769 reply_id: 20201[/import]

I’d rather have a technical description, personally. I’m sure I can find that somewhere else, however. [import]uid: 30657 topic_id: 5769 reply_id: 20416[/import]

[lua]physics[/lua] is a module that you’re calling functions from

whereas [lua]circle[/lua] and [lua]ground[/lua] are instances of an object that you’re calling functions from

something like that.

For the benefit of C++ users, in Lua a colon (:slight_smile: means member access requiring an object (dot or arrow in C++), while a dot (.) means static access (double colon in C++).
http://www.bresciascienza.it/erix/progutil/gpeddler2/help/oo.html

you didn’t call [lua]physics:start()[/lua] for instance
[import]uid: 6645 topic_id: 5769 reply_id: 21057[/import]

I had a similar problem to Dsavi, but when I change the : to a . in my code I get the following error:

“ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’”

Any ideas why this happens?

[import]uid: 38000 topic_id: 5769 reply_id: 45088[/import]

Lines 10 and 11 should be:

physics.addBody(ground, “static”, {friction = 0.5, bounce = 0.3})
physics.addBody(circle, {density = 1.0, friction = 0.3, bounce = 0.2, radius = 50})

In your code, you were using ‘:’ instead of ‘.’

The ‘:’ (colon) syntax is syntactic sugar where the table gets passed as an implicit 1st argument to the function. So

object:foo( 1, 2, 3 )

is equivalent to:

object.foo( object, 1, 2, 3 )

assuming object.foo is a function.
[import]uid: 26 topic_id: 5769 reply_id: 45093[/import]

I now understand the difference between ‘:’ and’.’, but even when the code is written as

physics.addBody( object, { tableValues }  

I did not add any table values other than the “collisionFilter” because I only wanted to use the physics to enable the collision filters. Could that be the the reason for my errors?
Here is my code:

local sharkCollisionFilter = {categoryBits = 1, maskBits = 6}  
local torpedoCollisionFilter = {categoryBits = 2, maskBits = 1}  
local diverCollisionFilter = {categoryBits = 4, maskBits = 1}  
physics.addBody( shark, {filter = sharkCollisionFilter })  
physics.addBody( torpedo, {filter = torpedoCollisionFilter })  
physics.addBody( diver, {filter = diverCollisionFilter})  

One thing I love about Corona is how founders are willing to come and help developers with in the forums. Thanks for your help with this! [import]uid: 38000 topic_id: 5769 reply_id: 45295[/import]