views:

134

answers:

3

There's a joke in there somewhere.

Anyhoot. In the following code, the setForceVector method has no actual effect on the value of member it's attempting to change. By checking the log, I can see the function is being called (by another object handling to a touchEvent).

I've used NSLog to check that the forceVectorfromControls is actually coming across as expected and it is.

If I set the value of forceVector in the init or step methods it works as intended. But for some reason, it does nothing in the setForceVector method.

cpVect is a C struct, does that have anything to do with it?

http://pastebin.com/m78f3d63e

I'm stumped.

A: 

Shouldn't cpVect be a pointer (line 10)?

Don Werve
apparently not, that throws up an error. I'm told because it's a C Struct.
gargantaun
There's no reason why it should be a pointer.
Chuck
A: 

@synthesize will try to produce another accessor method, though I'm not sure what happens when the two conflict. Have you tried not synthesizing the setter? Alternatively, could you set a watchpoint on the variable and see what's changing it for you?

Graham Lee
sorry, yes, I had already commented it out. Not sure how it got into the pastebin code. Will take it out now. And it still doesn't work. When I call the method setForceVector and log the value of forceVector, I get what I'm looking for. But when I log the value inside step, it's {0,0}
gargantaun
also, according to cocoadevcentral, in the Learn Objective C tutorial, It's OK to use @sysnthesize and declare your own method too. Apparently @synthesize only create accessors if there are non available.
gargantaun
+1  A: 

This smells very strongly of having two different objects without realizing it. Try logging self in the methods and see if it's the same GameLayer doing all of this.

Chuck
i feel so ashamed.
gargantaun