Page 1 of 1

setData not working

Posted: Mon Apr 16, 2012 6:56 pm
by mluds
I'm using LOVE version 0.8.0 and when I do something like this

Code: Select all

shape = love.physics.newRectangleShape(100, 100)
shape:setData("Data")
I get an error saying "attempt to call method 'setData' (a nil value)".

Any suggestions? I was thinking it had to do with the fact that newRectangleShape returns PolygonShape rather than Shape.

Re: setData not working

Posted: Mon Apr 16, 2012 7:24 pm
by tentus
Welcome to the wonderful world of incomplete documentation! Boolsheet is busting it out like a champ, but there's still a long way to go.

In the meantime, what you want is Fixture:setUserData.

Re: setData not working

Posted: Mon Apr 16, 2012 7:26 pm
by eyeck
Shape:setData no longer seems to even exist in 0.8.0, despite the docs not saying anything about this as far as I can see. Fixture:setUserData, on the other hand, works more or less as setData used to. So, you can add your data to the corresponding fixture using Fixture:setUserData instead. If you will be using the data in the collision callbacks, the first two parameters to each collision callback are the fixtures in the collision. So, if you have a callback that's something like "addCollision( a, b, coll )" then:

Code: Select all

function addCollision( a, b, coll )
    print( a:getUserData() )
end
will print out whatever userData you stored in a's fixture.

Re: setData not working

Posted: Mon Apr 16, 2012 10:14 pm
by mluds
I got it working using Fixture:setUserData. Thanks!