GUI Label position

Started by ℛḝξ☂, Jan 21, 2017, 11:33 AM

Previous topic - Next topic

ℛḝξ☂

I am using GUI Label to create a label to show team scores and current base.
Here is my code:
Client side
g_option3 = GUILabel();
function Script::ScriptLoad( )
{
   //score message ( I just copied the code for showing scores. )
       g_option3.Text = "Current Score: Reds: 0 || Blues: 0";
       g_option3.TextColour = Colour( 255, 0, 255 );
      g_option3.FontSize = 15;
      g_option3.Pos = VectorScreen( sizex * 0.8, sizey / 2 - 65 );
}
function Server::ServerData( stream )
{
 local strint = stream.ReadInt( );
 switch( strint.tointeger( ) )
{
case 4 :
    local txt = stream.ReadString();
    g_option3.Text = txt;
     break;
}
}

Server side
function GUITeamScore()
{
// this function will be called everytime the scores change.
    local data = Stream();
    data.WriteInt( 4 );
    data.WriteString( "Current Score: Reds: " + RedScore + " || Blues: " + BlueScore );
    data.SendStream( null );
}

This works fine. But you can see the following pics, label after being changed, its position seems moved a little, is it something changed it?

Label before being changed.
Label after being changed.
I may be a slow walker but I am always walking.

Shadow

I am not going to dive into the issue but rather point out that what you are doing is highly inefficient in terms of bandwidth. Mainly because you are sending an entire string when you could just send 1 packet with a given identifier and the score of the 2 teams. I'd suggest you to rework your server-client packets in something less wasteful for you and your players, such as:

Storing the packet identifiers, code for the client (can be used on the server side aswell, for identification purposes):
enum PacketIdentifiers
{
             PacketScoreUpdate,
             PacketGameStatusUpdate
};

..which you might then access as PacketIdentifiers.PacketGameStatusUpdate. Rename them as you wish but make sure they still make sense to you without having to look back at their definition.

The server would then be sending a packet whenever the game starts/ends, like this:

function UpdateGUIGameStatus( b_Started )
{
          local data = Stream();
          data.WriteByte( PacketIdentifiers.PacketGameStatusUpdate );
          data.WriteByte( b_Started );
          data.SendStream( null );
}


function UpdateGUIGameScore( red_score, blue_score )
{
       local data = Stream();
       data.WriteByte( PacketIdentifiers.PacketScoreUpdate );
       data.WriteInt( red_score );
       data.WriteInt( blue_score );
       data.SendStream( null );
}

Notice how I use the WriteByte method. And there's a reason to it. Bytes are, as you might've guessed, 1 byte. That's 8 bits of space. Ints (short for integers) are 4 bytes (because they can hold large numbers, 1 byte can hold a maximum of 255, that's 2 ^ 8 - 1).

Then on the client you'd have two functions, one for reading the status update and updating the GUI accordingly (like you did show us in your picture, with the Base is not active text), and one for updating the score.

function ProcessGUIUpdate( stream )
{
        local byteUpdate = stream.ReadByte( );
        switch( byteUpdate )
        {
                case PacketIdentifiers.PacketGameStatusUpdate:
                { // enter a new scope
                      g_option3.Text = "Game status: " + ( ( stream.ReadByte()  == 1 ) ? "Started" : "Not started" ); // elvis operator, google more about it if you wish
                }
                break;

               case PacketIdentifier.PacketScoreUpdate:
               {
                           g_option3.Text = "Reds: " + stream.ReadInt( ) + " || Blues: " + stream.ReadInt();
               }
               break;

              default:
              break;
      }
}

By the way, I wrote all of this off the top of my head so there might be a few errors here and there.

QuotePS:is trash is ur home language??

ℛḝξ☂

Quote from: Shadow on Jan 21, 2017, 12:19 PMI am not going to dive into the issue but rather point out that what you are doing is highly inefficient in terms of bandwidth. Mainly because you are sending an entire string when you could just send 1 packet with a given identifier and the score of the 2 teams.
For the team scores, I'd send byte with this easier way. however for showing status of base, not only do I want to send the status, also, I want to send a base info message like: "ID46, Tommy Mansion". this situation is send the entire string the only way to show something like this?
and thanks for your patient telling, i've learnt a lot. :)
I may be a slow walker but I am always walking.