Send and receive data
Send#
WSNET provides several functions to send data to the other players.
All send functions accept these 3 arguments:
msg_id - The message ID. You will use this to identify the kind of message received from a player.
player_id - The ID of the player which to send the message (use 255 to send to all lobby players).
data - Data to send (string/number/array/buffer/etc).
For example, if you want to send a chat message to a player.
The full list of the available functions:
net_send()- Buffernet_send_string()- Stringnet_send_string_array()- Array of stringsnet_send_number()- Numbernet_send_number_array()- Array of numbersnet_send_byte()- Bytenet_send_byte_array()- Array of bytesnet_send_array()- Array of numbers/strings/booleans/int64net_send_list()- List of numbers/strings/booleans/int64net_send_map()- Map of numbers/strings/booleans/int64
Receive#
Listen for incoming messages:
This will register a callback function for the specific message ID, that will be executed every time the player receives a message.
Example: