Page 1 of 1

Help With Code

Posted: Wed Jan 04, 2012 2:47 pm
by Wellington2k
Hello.

I just started to try and learn how to use Chipmunk, but I've run into a problem.

When I try to run this code (used for updating the shapes):

Code: Select all

- (void)tick:(NSTimer *)timer {
	cpSpaceStep(space, 1.0f/60.0f);
	cpSpaceHashEach((*space).activeShapes_private, &updateShape(nil, nil));
}
I get this error:
address expression must be an lvalue or a function designator

The original code used for this was:

Code: Select all

- (void)tick:(NSTimer *)timer {
	cpSpaceStep(space, 1.0f/60.0f);
	cpSpaceHashEach(space->activeShapes, &updateShape, nil);
}
But that gave me 8 errors:
"_cpSpaceStep", referenced from:

"_cpSpaceHashEach", referenced from:

"_cpInitChipmunk", referenced from:

"_cpSpaceNew", referenced from:

"_cpBodyNew", referenced from:

"_cpSpaceAddBody", referenced from:

"_cpCircleShapeNew", referenced from:

"_cpSpaceAddShape", referenced from:

I don't know what to do, sense I just started.

Any help?

Re: Help With Code

Posted: Wed Jan 04, 2012 4:00 pm
by slembcke
Calling cpSpaceHashEach(space->activeShapes, ... ) was never recommended as both the function and that field were private. The misinformation would always spread faster than I could point out their private status. In Chipmunk 6, I mangled the names of private things to include _private.

You should be calling cpSpaceEachShape() instead. However, I would also strongly recommend not to tie your sprites to your shape. You should be associating bodies with sprites instead so that you don't limit yourself to one shape per body. I also don't recommend iterating the space to update sprites at all. You really should be storing a list somewhere else so that you can use the userdata pointers for your game object instead of wasting it on sprites. It doesn't really matter if you don't use any callbacks though.

As for the errors you are getting, those are linker errors. You forgot to include Chipmunk in your project (or forgot to tell it to link to it). The reason why the errors go away is because you made a compile error with &updateShape(nil, nil) and the linker never runs. You are passing a function pointer to the each function, not calling the function. (you also don't need the &)

Re: Help With Code

Posted: Wed Jan 04, 2012 8:29 pm
by Wellington2k
As you may already guess I have not used Chipmunk before.

So, if you could, tell me this in more detail.

By the way I can't find the files I'm missing. I put the whole Chipmunk folder in my project.

Also, could you put a link for a tutorial of Chipmunk.

Thanks.

I changed the hasheach code with:

Code: Select all

cpSpaceEachShape(space, nil, nil);
but where do I tell it to update the shape?

Re: Help With Code

Posted: Thu Jan 05, 2012 3:46 pm
by slembcke
Check that the chipmunk source files are included in your target's "Compile Sources" phase under the "Build Phases" tab.

Anyway, you should use the xcode/iphonestatic.command script that comes with Chipmunk to build a static library (I'm assuming that you are doing iPhone development?). Including the full Chipmunk source into your project can create a lot of headaches.