Jump to content

SendNetworkString: Difference between revisions

Added a second example
m (Tweaked example slightly)
(Added a second example)
Tag: Source edit
Line 26: Line 26:
}
}


Script "ReceiveStringOnServer" (int str) NET
Script "ReceiveStringOnServer" (int string) NET
{
{
     Print(s:"Received '", s:str, s:"' from a client");
     Print(s:"Received '", s:string, s:"' from a client");
}
</syntaxhighlight>
 
Because the server has no clue which player sent the script, we need to append that data to the string.
<syntaxhighlight lang="c">
Script "ClientScript" (void) CLIENTSIDE
{
    // One way to append the PlayerNumber is to write it as a character to the start of the string
    // We need to +1 because 0 would terminate the string early
    NamedSendNetworkString("ReceiveStringOnServer", StrParam(c:(ConsolePlayerNumber()+1), s:"Hello Server"));
}
 
Script "ReceiveStringOnServer" (int packet) NET
{
    int plynum = GetChar(packet, 0)-1;
    str string = StrRight(packet, StrLen(packet)-1);
    Print(s:"Received '", s:string, s:"' from client ", d:plynum);
}
}
</syntaxhighlight>
</syntaxhighlight>


[[category:ACS functions]]
[[category:ACS functions]]