Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problems with packets.  (Read 2941 times)

0 Members and 1 Guest are viewing this topic.

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Problems with packets.
« on: July 05, 2012, 08:57:39 pm »
This is a part of my code,
void GlobalWorld::SendPlayers(sf::TcpSocket * client) {
        if(this->Players!=NULL){
        sf::Packet SentPacket;
        SentPacket << this->numPlayers;
        for(int index=0;index<this->maxPlayers;index++){
                if(this->Players[index].Connected){
                        //the current player is connected, add the data to the packet
                        SentPacket << Players[index].Position.x << Players[index].Position.y << Players[index].Rotation << Players[index].Health << Players[index].Name;
                }
        }
        int x;
        float z;
        SentPacket >> x >> z;
        std::cout << x << z;
        client->send(SentPacket);
}
}

The x,z part is used for debugging so every time I call that function z will result as undefined float, however if I print the value which z should be (Players[index].Position.x, Position is vector2f) it prints the real result.
But the x matches with the numPlayers member of the GlobalWorld.
What's wrong?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets.
« Reply #1 on: July 05, 2012, 10:44:33 pm »
Have you checked that the following line is executed at least once?
 SentPacket << Players[index].Position.x << ...
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: Problems with packets.
« Reply #2 on: July 05, 2012, 11:15:53 pm »
Yes if I make it print the Players[index].Position.x on that same block it'll print it correctly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets.
« Reply #3 on: July 06, 2012, 08:19:16 am »
You should try to reproduce this problem in a complete and minimal code, so that we can test it.
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: Problems with packets.
« Reply #4 on: July 06, 2012, 11:56:17 am »
Ok, I got it working.. Sorry for wasting your time :P

It was obvious mistake, the Connected member was never set to true since I modified the constructor a bit :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problems with packets.
« Reply #5 on: July 06, 2012, 12:10:24 pm »
If Connected was always false, how did you succeed to "print the Players[index].Position.x on that same block correctly"?
Laurent Gomila - SFML developer

kapesu8

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: Problems with packets.
« Reply #6 on: July 06, 2012, 12:39:53 pm »
Sorry, I might have been printing it on the one outer block from that.

 

anything