Help! Sessions and rooms

Posted by Honey_badger
Hello again!

I have a problem with sessions. I wanted to create a game for 5 people for each room, so I decided to use this code:

for(im = 1; im <=10; im +=1){
show_message('Search')

if(gms_session_exists(im)){
if (gms_session_player_count(im) <= 5){
gms_session_join(im);
show_message('Done');
room_goto_next();
break
}}else{
gms_session_create(im);
show_message('Created onei');
room_goto_next();
break
}

if (im == 10) {
show_message('Sorry, no match found.');
}
exit;
}

But when I try to log in from two different players, he constantly writes that nothing was found and a new session is being created. Although there should have been a connection with the session with the player. As a result, players cannot communicate with each other, even if they were connected to the same session and need to interact. I don't know what to do. I tried all the possibilities and methods, but nothing came out. Even without sessions, the connection between them disappears...The connection without a session not works

Update:

I deleted the room and created a new one, now the connection without a session works. But I still need to create a working session! When I try to connect to my player, they write to me:

"You tried to join a session with ID=1, but this session does not exist. Existing IDs are: 4, 3.You are currently in a session with ID=4"

Always writes that the ID does not exist, although they are created in a loop. Please help me solve the problem with sessions!

What should I do in this situation? Maybe there is some more code for sessions?

Tell me more, please, how to make it so that it was impossible to enter the room when the game started

Replies (1)

Last message on 4 Sep 2021

Size43 (Administrator) on 4 Sep 2021, 16:05:28
gms_session_exists uses a session_id, while gms_session_create uses a session type. You cannot control the IDs of sessions, only their types. If you want to enumerate over sessions, you will have to use gms_session_id to get the session_id of a certain session.

You can see an example of how to enumerate over sessions in gms_session_type.

By the way, you might sometimes see your code working if you get lucky with session ID assignments. If the first session happens to have ID 1 and the second happens to have ID 2, etc., it will look like your code works.