setData not working

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
mluds
Prole
Posts: 2
Joined: Mon Apr 16, 2012 6:50 pm

setData not working

Post by mluds » Mon Apr 16, 2012 6:56 pm

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.

User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: setData not working

Post by tentus » Mon Apr 16, 2012 7:24 pm

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.
Kurosuke needs beta testers

eyeck
Prole
Posts: 6
Joined: Mon Apr 16, 2012 4:55 pm

Re: setData not working

Post by eyeck » Mon Apr 16, 2012 7:26 pm

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.

mluds
Prole
Posts: 2
Joined: Mon Apr 16, 2012 6:50 pm

Re: setData not working

Post by mluds » Mon Apr 16, 2012 10:14 pm

I got it working using Fixture:setUserData. Thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], ivan and 8 guests