Re-joining the default session

If you're using sessions, you might want to have players re-join the default session at some point. New players will also join this new session. You can do this by adding a new script:

///gms_session_find_by_type(type)

// Search for the first session that has the same type as argument0

for(var i = 0; i < gms_session_count(); i++)
{
    if(gms_session_type(gms_session_id(i)) == argument0)
    {
        return gms_session_id(i);
    }
}
return -1;


This script searches through all sessions and checks if there's a session with the type provided as an argument. If there is, the first session matching that type is returned.

You can then use this script to have a player re-join the default session, which has a session type of 0, as follows:

var type = 0;
var session_id = gms_session_find_by_type(type)
if session_id == -1
{
    gms_session_create(type)
} else {
    gms_session_join(session_id)
}


You could also use this same technique if you want to create a fixed set of sessions, for example a "Normal" and a "Special" mode. Before joining the game, you show the player a menu to choose between normal and special. If they choose normal, you join a session with type 1, and if they choose special you join a session with type 2 (just re-use the code above, and change the value of the type variable).

Replies (0)

Last message on -