Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I send an array of integers via GKSession bluetooth
    primarykey
    data
    text
    <p>I have a problem with sending an array of integers via GKSession.</p> <p>This is how I did it:</p> <p>To send it.</p> <pre><code>-(void)sendData { NSMutableArray *myArray = [[NSMutableArray alloc] init]; [myArray addObject:[NSNumber numberWithInteger:snakeHead.position.x]]; [myArray addObject:[NSNumber numberWithInteger:snakeHead.position.y]]; [myArray addObject:[NSNumber numberWithInteger:direction.x]]; [myArray addObject:[NSNumber numberWithInteger:direction.y]]; [myArray addObject:[NSNumber numberWithInteger:bodyOffsetX]]; [myArray addObject:[NSNumber numberWithInteger:bodyOffsetY]]; [myArray addObject:[NSNumber numberWithInteger:amountBodies]]; NSData* encodedArray = [NSKeyedArchiver archivedDataWithRootObject:myArray]; [snakeSession sendData:encodedArray toPeers:snakePeers withDataMode:GKSendDataReliable error:nil]; [encodedArray release]; } </code></pre> <p>The sendData function is called from a scheduler.</p> <p>To receive it.</p> <pre><code>-(void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context { NSArray *hisArray = [NSKeyedUnarchiver unarchiveObjectWithData:data]; snakeHead2.position = ccp([[hisArray objectAtIndex:0] integerValue], [[hisArray objectAtIndex:1] integerValue]); direction2 = ccp([[hisArray objectAtIndex:2] integerValue], [[hisArray objectAtIndex:3] integerValue]); bodyOffsetX2 = [[hisArray objectAtIndex:4] integerValue]; bodyOffsetY2 = [[hisArray objectAtIndex:5] integerValue]; amountBodies2 = [[hisArray objectAtIndex:6] integerValue]; } </code></pre> <p>This does not work and the game crashes.</p> <p>So what am I doing wrong here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload