Sign In Register

How can we help you today?

Start a new topic

Starting Realtime with one player


I'm doing matchmaking + realtime for my card game and I want to be able to start RT sessions with only one player (to avoid duplicating code and keep my structure linear)

current flow is:

  • player can start matchmaking either alone or with friends invited earlier, to do this I have a LogEventRequest with "Spark.getConfig().getMatchConfig(data.match).createPendingMatch(data.matchGroup, skill, playerData)", where playerData is curent player + players loaded from Ids passed by client
  • player(s) receive a MatchFoundMessage and starts an RT session
  • client code sends moves to server through RT, server relays packets to all clients (including sender) and clients react to player moves when they receive them (including moves sent by themselves)
i'm trying to match fake players with this code in MatchNotFoundMessage (global):


var player = Spark.getPlayer();
var data = Spark.getData();

 var playerData = [player];
    var matchCfg = Spark.getConfig().getMatchConfig(data.matchShortCode);
    var maxp = matchCfg.getMaxPlayers(); // this is 4
    var bots = Spark.runtimeCollection("bots").find(); // bots collection contains a list of fake player ids
    while (playerData.length < maxp) {
        var id = bots.hasNext() ? : null;
        if (!id) { 
// create a fake player and add it to bots collection
// this is temp, I plan to have a pool of users and selecting randomly from that
            var rr = new SparkRequests.DeviceAuthenticationRequest();
            rr.deviceId = "server-"+ Spark.runtimeCollection("bots").count();
            rr.deviceOS = "BOT";
            id = rr.Send().userId;
        var bot = Spark.loadPlayer(id);
    Spark.getLog().info({before:"pm",players:playerData.length}); // length is 4
    var pm = matchCfg.createPendingMatch(data.matchGroup , DataModel.User.Current().Skill, playerData);
    Spark.getLog().info({after:"pm",players:pm.getMatchedPlayers().length}); // length is 1

 but bots are not added to the pending match. I tried to hardcode the ID of another (real) player but is still not matching

is there a recommended way to force the creation of a match?

Best Answer

Hi Shah,

You can do it now. Set the minPlayer value in your match to 1  and send a MatchMakingRequest as a player and they will be in the match by themselves.



1 person has this question

Hi Mauro,

It's probably not a great idea to create a new bot each time you are doing this. You are just going to end up creating a new player each time a match is created which isn't Ideal. You should instead just create a minimal amount of bot accounts for this use and then when creating a pending match as a player include the bot account playerId so you can create it.


Spark.getConfig().getMatchConfig(shortCode).createPendingMatch(matchGroup, skill, players)


Are you getting a specific error when trying to attempt this with your custom code above ?



Hi Liam,

I am not creating a new user each time. the code above first looks for an available id in the "bots" runtimeCollection and creates a new player only if there are none (i.e. the first time it executed - I am still in the preview environment, I plan to put that in the "Game Published" system cloud code before I go live)

the code I run is exactly as you posted:   

var matchCfg = Spark.getConfig().getMatchConfig(data.matchShortCode);
// ... fill playerData with [player, bot1, bot2, bot3]
var pendingMatch = matchCfg.createPendingMatch(data.matchGroup , skill, playerData);

  I don't get any error,  but if I print pendingMatch.getMatchedPlayers().length it returns 1 - i.e. only myself. then I get another MatchNotFoundMessage after it expires (and it looped until I commented out the code)

(ps. everytime I post anything I land on an error page with a "We're sorry, but something went wrong." message and I have to go back to the index)

I'm not sure why the mechanics to create an RTSession and/or join/leave one are so opaque and only accessible within the context of matchmaking. I vote for exposing a much more straightforward api... like RequestCreateRTSession, RequestJoinRTSession, RequestLeaveRTSession.

1 person likes this

How do I request to leave the current RTSession(not by disconnect the interenet but by say click a button), currently I tried to use EndSessionRequest, but doesn't seem to work.

1 person likes this
Hey Mauro,

Starting a match with a single player is still in the backlog.
I'll update you when the work has started.



Hey Sean,

Please update me about single player match starting and other player can join same session. At the moment I am creating RPG game and for that I cannot make sure to get all players online on same time but we need to spawn as player joins room.

Will be waiting for your prompt reply.


Hi Shah,

You can do it now. Set the minPlayer value in your match to 1  and send a MatchMakingRequest as a player and they will be in the match by themselves.



Yes Liam, but when other player joins the match from other client it creates seperate RT session and have no info about first player and for checking I printed participants in current RT session it returns 1 only.

Shah, I think you just need to turn on "drop-in/drop-out" toogle in your match settings.

My scenario is when player A joins the room(GSMatch) which is having limit of 10 player, he can explore and move around the map by creating RT session. Other players joining same match should spawn in same environment and at joining should return callback matchupdated. Is it possible to start real time session for one player and after that other players can join that same RT session depending on GS Match in my case it is WorldCluster.

1 person likes this
Login to post a comment