-
-
Notifications
You must be signed in to change notification settings - Fork 16
API Documentation
Connects to the window.location address. Call this function before continuing using this extension.
Same as sio_connect()
but with the difference that you can connect to a different url.
Closes the current connection.
In case you've disconnected for whatever reason, you can use this function to reconnect to the server. (It will use the provided address from sio_connect()
or sio_connect_by_url(url:string)
(If connection is lost, socket.io will try re-connect by itself) You don't need to implement this feature by yourself.
Creates a new event, but you have to create a callback to your client in order to access the received data.
ATTENTION you have to follow this naming scheme: gmcallback_sio_on_**eventName**
. Where **eventName**
is replaced by the name you have specified above as an argument. Event names are case sensitive!.
Example:
# create event
sio_addEvent("create_player");
create a new script called: "gmcallback_sio_on_create_player"
The callback script contains one argument argument0
, which is the packet data received from the server. If the server sends a JSON-object to the client, the client turns it automatically into a JSON-string. Otherwise it just passes the string right away.
In this example our argument0
is a JSON-string. To use the data, you've to decode the JSON-string to DSMap.
Example:
// Decode the received JSON string to DSMap
var data = json_decode(argument[0]);
// Access our data
var username = data[? "username"];
var playerID = data[? "id"];
var health = real(data[? "health"]);
..
Send your data to the server. eventName
is case sensitive! data
can be either a string or JSON-string.
In order to send a packet, follow the example below.
The data we send is a JSON-string.
Example:
var eventName = "create_player";
var username = "John Doe";
// This is our packet
var data = ds_map_create();
data[? "username"] = username;
data[? "x"] = x;
data[? "y"] = y;
sio_emit(eventName, json_encode(data));
ds_map_destroy(data);
If the game client is connected to the server it will return true
, otherwise false