Int Showing as Long Odd Value
- by Josh Kahane
Hi
I am trying to send an int in my iphone game for game center multiplayer.
The integer is coming up and appearing as an odd long integer value rather than the expected one.
I have this in my .h:
typedef enum
{
kPacketTypeScore,
} EPacketTypes;
typedef struct
{
EPacketTypes type;
size_t size;
} SPacketInfo;
typedef struct
{
SPacketInfo packetInfo;
int score;
} SScorePacket;
Then .m:
Sending data:
scoreData *score = [scoreData sharedData];
SScorePacket packet;
packet.packetInfo.type = kPacketTypeScore;
packet.packetInfo.size = sizeof(SScorePacket);
packet.score = score.score;
NSData* dataToSend = [NSData dataWithBytes:&packet length:packet.packetInfo.size];
NSError *error;
[self.myMatch sendDataToAllPlayers: dataToSend withDataMode: GKMatchSendDataUnreliable error:&error];
if (error != nil)
{
// handle the error
}
Receiving:
SPacketInfo* packet = (SPacketInfo*)[data bytes];
switch (packet->type)
{
case kPacketTypeScore:
{
SScorePacket* scorePacket = (SScorePacket*)packet;
scoreData *score = [scoreData sharedData];
[scoreLabel setString:[NSString stringWithFormat:@"You: %d Challenger: %d", score.score, scorePacket]];
break;
}
default:
CCLOG(@"received unknown packet type %i (size: %u)", packet->type, packet->size);
break;
}
Any ideas? Thanks.