Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7004239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:10:24+00:00 2026-05-27T21:10:24+00:00

I’m building a prototype game and have some multiplayer functionality hooked up. I am

  • 0

I’m building a prototype game and have some multiplayer functionality hooked up. I am running into an issue with sending a float over the wire though. Curious if anyone has run into this, or can tell me what the issue is.

The structure that I send looks like this:

struct TRMessageHeader {
  int length;
  int code;
};

struct TRMessagePushPeer {
  struct TRMessageHeader header;
  float force;
};

My code that sends it over the wire looks like this:

- (void) testFloat:(int) floatValue {
  struct TRMessagePushPeer message = {0};
  message.header.code = TRMessageCodePushPeer;
  message.header.length = sizeof(message);
  message.force = floatValue;
  NSArray * peers = [_session peersWithConnectionState:GKPeerStateConnected];
  NSData * data = [NSData dataWithBytes:&message length:sizeof(message)];
  NSError * error = NULL;
  [_session sendData:data toPeers:peers withDataMode:GKSendDataReliable error:&error];
}

My receiving code looks like this:

- (void) onPeerPushed:(NSNotification *) notification {
  NSDictionary * userInfo = [notification userInfo];
  NSData * messageData = [userInfo objectForKey:@"messageData"];
  struct TRMessagePushPeer * message = (struct TRMessagePushPeer *)[messageData bytes];
  NSLog(@"peer sent float :%f",message->force);
}

So the issue I’m having is if i call testFloat:0.4573, then the receiving peer’s float value is 0. If I call testFloat:1.3458 then the receiving peer’s float value is 1.

So it seems like it’s rounding down in the peer receive code but I’m not sure why.

I figure encoding the float with IEEE754 would work, but I would like to know why this doesn’t work as is before I encode it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:10:24+00:00Added an answer on May 27, 2026 at 9:10 pm

    - (void) testFloat:(int) floatValue

    …I think that would be your problem – you’re casting your float as an int in the method declaration. It will be automatically cast to an int when it is passed in. You will probably kick yourself once you see this!

    Change it to this:

    - (void) testFloat:(float) floatValue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.