Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I was trying to make a multiplayer Pong iOS app and ended up with this. It is almost good, except for one big bug. The 2nd player's paddle is moving the same way with yours. Basically, you're playing solo with a multiplayer score. I've struggled to see where I've failed, but without success.

the .m: https://gist.github.com/4682875 the .h: https://gist.github.com/4682903

share|improve this question

closed as off topic by palacsint, vikingosegundo, Brian Reichle, Yuushi, Glenn Rogers Feb 4 '13 at 7:40

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
This site is a place to get feedback on working code, not a place to find bugs in your code. Also we require code to be contained in your question, not a link to an external source. –  sepp2k Feb 4 '13 at 14:00
add comment

1 Answer 1

up vote 2 down vote accepted

I believe you've got an error here:

-(void)sendarray{
    NSData *data3 = [NSData dataWithBytes:gamedata length:(10+sizeof(float))];
    [self mySendDataToPeers:data3];
}

...you almost certainly want the length to be 10 * sizeof(float) there.

And a minor issue in this method:

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context{

    if(gamedata[2]==1) {
        gamedata[2]=0;
    }
    else{
        [data getBytes:gamedata];
        if(gameUniqueID >= gamedata[9]) {
            gamedata[8]=1;
        }
        else{
            gamedata[8]=0;
        }
        paddletwox = gamedata[5];
        [self draw];
    }
}

The [NSData getBytes:] call you are using there was deprecated in iOS 4.0. You should prefer using [NSData getBytes:length:] instead.

Not sure if fixing the first issue will fix the problem of the paddles moving incorrectly, but it's something to start with, at least.

share|improve this answer
    
that damn + was the problem ! I can't believe it and I can't thank you enough :D THANK YOU ! –  Daniel Feb 4 '13 at 8:47
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.