About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
Bug in order of parameters?
Author Message
mystara Offline
Member

Post: #1
Bug in order of parameters?
Gaah, I cannot seem to figure out this bug.

It seems that the bytes in my TCP message are being reversed somewhere.

Client side:
Code:
void Server::sendData(Vec pos)
{
    File f;
    f.writeMem();
    
    f.putByte(MY_MESSAGE);
    f.putFlt(pos.x); f.putFlt(pos.y);f.putFlt(pos.z);
    f.pos(0);
    
    Gui.msgBox("Pos is", S+pos);
    
    tcp.dataFull(f, f.size());
}

Server side:
Code:
if (connection.receive(0))
{
    connection.data.pos(0);
    Byte msgType = connection.data.getByte();

    if (msgType == MY_MESSAGE)
    {
        Vec pos = Vec(connection.data.getFlt(),
        connection.data.getFlt(), connection.data.getFlt());
        Gui.msgBox("Position", S + pos);
    }
}
Output at client: 1.0, 2.0, 3.0
Output at server: 3.0, 2.0, 1.0

No idea why :(
(This post was last modified: 06-12-2011 02:15 PM by mystara.)
06-11-2011 10:31 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Bug in order of parameters?
Vec(connection.data.getFlt(),
connection.data.getFlt(), connection.data.getFlt());
C++ sets function parameters from last to first, so do manually:
pos.x=getflt
pos.y=getflt
pos.z=getflt
06-13-2011 11:36 AM
Find all posts by this user Quote this message in a reply
mystara Offline
Member

Post: #3
RE: Bug in order of parameters?
Ah, thanks. I never would have figured that out grin
06-13-2011 08:05 PM
Find all posts by this user Quote this message in a reply
Post Reply