Sign In Register

How can we help you today?

Start a new topic

RTSession all players connected and ready


I am setting up a real time game with GameSparks and I read a lot of your tutorials and examples already. However, I am still having trouble with a couple things related to matchmaking, connecting to match and starting the match.

So say I create a match for 2-10 players. Then the match is found with 4 players. I am making a deterministic lockstep game, so the server sends the updates to the players which interpolate gamestate deterministically themselves, which means I need to start sending updates only when I am 100% sure all clients are connected and ready to calculate those updates locally. My problem is, I am having a hard time to know when that is true.

I have a match that could have up to 10 players, but was filled with 4. If I do RTSession.getPlayers, from what I understood, I only get the currently connected players, which could be any number between 1 and 4 right? How do I know I am getting the total number of players?  I was thinking of having the players send a "I am ready" packet once the game scene is fully loaded, so the server stores that player peer id X is ready... however, how can the server know "all" players are ready? is there a concept of "maximum number of players for this match is 4"? If I only get 3 "I am ready", but the 4th device is so slow its not even connected yet, how do I know there is another player coming?

I might be missing something, I am new to gamesparks so sorry for my noobery.


1 Comment

Ok so, after some testing I ended up going with the following solution (for now):

My realtime script has a variable totalPlayers, which I populate the following way:

    var sessionId = RTSession.getSessionId();
    var playerId = player.getPlayerId();
    RTSession.newRequest().createMatchDetailsRequest().setMatchId(sessionId).setPlayerId(playerId).setRealtimeEnabled(true).send(function(response) {
        if (typeof response.opponents != 'undefined')
            totalPlayers = response.opponents.length + 1;
            totalPlayers = 1;
        RTSession.getLogger().debug("Setting total players to " + totalPlayers);


With this, every time a new player sends a "Player Ready" message, I add them to a "readyPlayers" array and when the readyPlayers array is as large as "totalPlayers", I start updating the game for everyone... now... seems to be working with the very very limited testing I did... but part of me doesnt think this is the smart way of doing this? lol

Login to post a comment