Usage: gms_script_set_session_change ( script_id )


Sets the script that will be called when the player's session_id changes.

The script script_id should take 1 argument.
1: The new session_id

Replies (9)

Last message on 7 Feb 2021

L4Vo5 on 31 Jan 2021, 21:58:12
The game seems to change session several times. I'm making a board game, and I've explicitly done a show_debug_message before calling gms_session_create_ext and before gms_session_join, and indeed they only ever get called once, yet the session change script is triggered several times, seconds apart, resetting the state of the board on at least one end.
I've also noticed the script getting called two or three times at the start of the game, when joining the type 0 session, but that doesn't seem to be a problem.
Is there anything that could cause that? maybe that I'm opening two instances of the game on the same computer to test? or that I made the player object persistent? or that I keep switching tabs?? I'm puzzled
L4Vo5 on 1 Feb 2021, 03:46:40
Oh... this still happens, but my specific problem was solved by only conditionally changing the room in the script :P yeah, I guess that shouldn't be a problem if I take it into account for the future
Size43 (Administrator) on 7 Feb 2021, 14:52:33
The session change script might run multiple times if new session information is received; If you want to detect the exact moment you change sessions, you should compare the old session ID with the new one you just received. If they differ, you just changed sessions.

And yes, I'm aware the naming is quite unfortunate here -- something like gms_script_set_session_info_received would be much better.
muniznico on 10 May 2018, 19:37:43
Hi Size,

I have a problem. i have set a simple script to handle a session change.

//in GMS object


var new_id = argument0;
if(new_id != gms_session_current_id()){
session_type = gms_session_type(new_id);
if(session_type == 1){
room_transition = instance_create(0,0,obj_screen_transition);
room_transition.next_room = rm_wait_screen;
else if(session_type == 0){
room_transition = instance_create(0,0,obj_screen_transition);
room_transition.next_room = rm_main_menu;

but when i call :


the script always pass by the "session_type == 0" case...
But after that, i check the session type (with a show_message), and it returns 1.

I can't handle session creation because of that.
Can you help me please ?
Size43 (Administrator) on 27 May 2018, 16:37:00
What version of GameMaker Server are you using? Windows or all?
muniznico on 29 May 2018, 08:49:17
I'm using the windows version (I can't seem to login with the all version). I found a way to work around my problem, but if you know why is this happening, i would still be glad to know the answer ;)

By the way, i have another question. Sometimes, the function "gms_session_count()" takes a really long time to find the active sessions in my game. I know there are multiple sessions running by my friends (or me in multiple game runs), but when i join my lobby room, the function only find the main session (type 0). I'm executing the function in the step event while i don't find a session that fit the requisite type and tag, but it can take to 6~7 minutes to find the right sessions. Sometimes it works immediately, sometimes not.

Is it a normal behavior ? Maybe because the server is busy ?

Thanks by advance for your reply.
Size43 (Administrator) on 1 Jun 2018, 16:28:27
(Maybe the all version isn't working because the call to gms_network in the async networking event is missing?)

If you're able to reproduce the session behaviour at least semi-regularly please send your project (or something similar that has the same issue) to so I can take a look.

You could also try to force a session update using gms_request_resource.
Dublann on 15 Mar 2017, 20:06:23
Hi Size,

To use it, should be like this?
somewhere in the code


Because it is connected to a random session id instead of the session 1.

Size43 (Administrator) on 22 Mar 2017, 18:50:20
Session IDs are random, you can only change the session type (when creating a new session).