ChainShape Help

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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

ChainShape Help

Post by Ranguna259 »

Hello everyone, so I've been trying to do a ChainShape but it doesn't seem to work, here's how I coded it.

I have a variable, a, which has all the shape's coordinates from the first to the last:

Code: Select all

a=10,10,20,30,30,40,40,10
And I want to create a ChainShape with that variable, like this:

Code: Select all

shape.b=love.physics.newBody(world, 25,25,'static')
shape.s=love.physics.newChainShape(a)
shape.f=love.physics.newFixture(shape.b,shape.s)
but it gives me a blue screen with a box2d error, saying "count >= 3"

All codes are in their appropriated functions.

I want to know what I am doing wrong, and if you can could you write a little exemple on how to do a chainshape ? The wiki doesn't have one and I don't realy understand how it works. :?

Thanks for reading, and if this post was approved then thank you mod for approving it ^^
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: ChainShape Help

Post by micha »

Shouldn't it be

Code: Select all

a={10,10,20,30,30,40,40,10}
and

Code: Select all

shape.s=love.physics.newChainShape(false,a)
?
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: ChainShape Help

Post by riidom »

Wouldn't this place the table as first parameter, where a number is expected, and leave all the other parameters to nil?

On a more general side, I would like to know, how I can extract values of a table into the parameter list of a function.
(either like in this example, or e.g. {200,100,50} into love.graphics.setColor)

Ranguna, the problem is if you write a = 1, 2, 3 then a is 1, while 2 and 3 just get skipped.

Edit: Like this it works

Code: Select all

a={10,10,20,30,30,40,40,10}

shape.s=love.physics.newChainShape(false,unpack(a))
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: ChainShape Help

Post by Ranguna259 »

riidom wrote:Wouldn't this place the table as first parameter, where a number is expected, and leave all the other parameters to nil?

On a more general side, I would like to know, how I can extract values of a table into the parameter list of a function.
(either like in this example, or e.g. {200,100,50} into love.graphics.setColor)

Ranguna, the problem is if you write a = 1, 2, 3 then a is 1, while 2 and 3 just get skipped.

Edit: Like this it works

Code: Select all

a={10,10,20,30,30,40,40,10}

shape.s=love.physics.newChainShape(false,unpack(a))
Yep that did the trick, as for your question then I'm thinking that it is the same process as the one you've explained, like so:

Code: Select all

color={200,100,50}
love.graphics.setColor(unpack(color))
You've said that "a" is 1 in your exemple but I don't think it goes like that, I think that "a" is (1,2,3) but when you use it in chainshape or any other code without the "unpack()" code, chainshape will identify (1,2,3) as the first coodinate and not just 1. löve might be lovely, but it's not bugfree ;)

Anyways thanks for everyone's help, my problem has been resolved.
Thanks again :megagrin:
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: ChainShape Help

Post by Robin »

Ranguna259 wrote:You've said that "a" is 1 in your exemple but I don't think it goes like that, I think that "a" is (1,2,3) but when you use it in chainshape or any other code without the "unpack()" code, chainshape will identify (1,2,3) as the first coodinate and not just 1. löve might be lovely, but it's not bugfree ;)
No. riidom was right.

Code: Select all

a, b, c = 1, 2, 3 -- now a == 1, b == 2, c == 3
d = 1, 2, 3 -- now d == 1
e, f, g = 1 -- now e == 1, f == g == nil
Lists in Lua are a really fragile thing. The only thing you can use them for is multiple assignment (like in my first example), multiple return values and multiple trailing arguments to functions. Try anything else with them, and they get truncated.

This is not a bug in LÖVE, this is standard and expected behaviour of Lua.
Help us help you: attach a .love.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: ChainShape Help

Post by Ranguna259 »

Robin wrote:
Ranguna259 wrote:You've said that "a" is 1 in your exemple but I don't think it goes like that, I think that "a" is (1,2,3) but when you use it in chainshape or any other code without the "unpack()" code, chainshape will identify (1,2,3) as the first coodinate and not just 1. löve might be lovely, but it's not bugfree ;)
No. riidom was right.

Code: Select all

a, b, c = 1, 2, 3 -- now a == 1, b == 2, c == 3
d = 1, 2, 3 -- now d == 1
e, f, g = 1 -- now e == 1, f == g == nil
Lists in Lua are a really fragile thing. The only thing you can use them for is multiple assignment (like in my first example), multiple return values and multiple trailing arguments to functions. Try anything else with them, and they get truncated.

This is not a bug in LÖVE, this is standard and expected behaviour of Lua.
Oh I see, thanks for explaining that
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 206 guests