Thursday, April 28, 2011

What's happening to the value of my member?

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.

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

    gargantaun : apparently not, that throws up an error. I'm told because it's a C Struct.
    Chuck : There's no reason why it should be a pointer.
  • @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?

    gargantaun : 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.
  • 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.

    gargantaun : i feel so ashamed.

0 comments:

Post a Comment