SendNetworkString: Difference between revisions

Third example, as well as some tweaks
(Added a second example)
Tag: Source edit
(Third example, as well as some tweaks)
Tag: Source edit
 
Line 19: Line 19:


== Examples ==
== Examples ==
Sending a string from the client to the server:
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
Script "ClientScript" (void) CLIENTSIDE
Script "SendStringToServer" (void) CLIENTSIDE
{
{
    // Since the third argument (client) was not specified, the print will appear for all players
     NamedSendNetworkString("ReceiveStringOnServer", "Hello Server");
     NamedSendNetworkString("ReceiveStringOnServer", "Hello Server");
}
}
Line 28: Line 28:
Script "ReceiveStringOnServer" (int string) NET
Script "ReceiveStringOnServer" (int string) NET
{
{
     Print(s:"Received '", s:string, s:"' from a client");
     PrintBold(s:"Received '", s:string, s:"' from a client");
}
}
</syntaxhighlight>
</syntaxhighlight>


Because the server has no clue which player sent the script, we need to append that data to the string.
And now the other way around (server to client):
<syntaxhighlight lang="c">
Script "SendStringToClient0" (void)
{
    // Since the third argument (client) was specified, the string will only be sent to PlayerNumber 0
    NamedSendNetworkString("ReceiveStringOnClient", "Hello Client 0", 0);
}
 
Script "ReceiveStringOnClient" (int string) CLIENTSIDE
{
    Print(s:"Received '", s:string, s:"' from the server");
}
</syntaxhighlight>
 
Because the server has no clue which player sent the script, we need to append that data to the string:
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
Script "ClientScript" (void) CLIENTSIDE
Script "ClientScript" (void) CLIENTSIDE