(Solved) Trouble sending new session id to another player

Posted by SaitoZero
EDIT: I got it working by having Player B search for the session tag.

Okay so I'm trying to make a room-based matchmaking system. The goal is to simply have two players agree to fight each other, then create a new session and send both of them to the new session.

So far I've achieved simple interactions like:
- Player A queue up for battle
- Player B challenges Player A (using p2p message)
- Player A accepts and creates a new session
x Player A sends the new session ID back to Player B so that Player B can also join

However here is the problem, since the gms_session_create* functions moves you to the new session, I don't know why but when I tested it Player B can't receive the P2P message from Player A.

I was thinking about using a unique tag, and have Player B continuously looks for session with that tag, but I'm not sure how to go about implementing it, the documents have too little example.

Also a different question: is it normal for the script set inside gms_script_set_session_change(script) to be called repeatedly every 15 or so seconds? I put a show_message call to test it and removed all the session swapping related codes but the script is still getting called randomly (like the game keeps re-joining the same session)

Replies (1)

Last message on 6 Oct 2020

Size43 (Administrator) on 6 Oct 2020, 22:27:43
Glad to hear that you got it working.

You can indeed use unique session tags to matchmake. You could also have the client wait until the first session info update after gms_session_create, and then send that new session ID to the other player.

It's normal that your session change script is called every now and then. If I recall correctly, "session change" is really just whenever the client receives updated session info (for example player count changes) from the server. You can filter these events out by comparing the old and new session ID. If they are equal, there was no session change.