Int Showing as Long Odd Value
Posted
by
Josh Kahane
on Stack Overflow
See other posts from Stack Overflow
or by Josh Kahane
Published on 2011-01-15T18:14:48Z
Indexed on
2011/01/15
18:54 UTC
Read the original article
Hit count: 162
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.
© Stack Overflow or respective owner