Sign In Register

How can we help you today?

Start a new topic

Play realtime match against friend


I am developing an infinite runner style game where I want to create a Versus mode where players can challange their friends, or other players by their id to play a match against.

I was able to achieve this by creating an event to invite a player, and in its cloud code I could manually create a match by using

Spark.getMultiplayer().createMatchById([challengedPlayerId, Spark.getPlayer().getPlayerId()]);

 It worked pretty well, but there are a number of scenarios where this approach might not work well:

  • After inviting a friend, players can not cancel the invitation as far as I know as there is no way to delete a match
  • I used messages to let the challanged friend know of the invitation, and show an accept / decline dialog based on op code after receiveing it. I also could not figure out how to delete these messages if the player inviting the friend cancels.
After reading various forum posts I found that maybe creating a pending match instead of a match could solve most of my issues, however I failed to create a pending match in cloud code. After executing the following script:  

var pendingMatch = Spark.getConfig().getMatchConfig("VERSUS_MODE").createPendingMatch("group", 1, [Spark.getPlayer(), opponent]);

the pendingMatches collection in the NoSQL Explorer remained empty, even though the pendingMatch variable has been initialized. Another strange thing was that the  


 call returned 1 regardless that I used an array with a size of 2.

After starting a FindPendingMatchesRequest with the invited player I got a {"match":"NOT_IN_PROGRESS"} error.

I'm not sure if I'm even trying the right way, could you help me how I should implement such invitation based real time games? Also I found that GameSparks supports Challanges but I could not understand how I am supposed to use it, or even if they are supposed to be used alongside with matches.

Thanks in advance


Hi Balazs, 

Firstly, could you provide more information on the nature of these head to head games? 

Will players be playing in the same game at the same time, or simply competing with each others scores ? 

If the latter this could be done without a RealTime Implementation as only a progress and result comparison would be necessary. If you wish for the players to be inside of the same environment concurrently in Real Time then you will indeed be using RealTime MatchMaking. 

Challenges are utilized when the game play or behavior in question  is turn based or it is only the end result that matters. For instance if you wished players to compare scores and compete for a certain result then challenges are perfect. In fact they could be utilized alongside a RealTime Match if you wished to bet in game currency for instance. 

If you could provide me with some more info on the nature of your game I can point you in the right direction. 

Happy to help - Patrick. 

Hi Patrick, 

Thanks for the response.

I would like to create the versus mode in a way that players can play in the same level at the same time and they can see each other as well (but cannot really interact witheach other).

I understand that this would require Game Sparks Realtime. But as far as I know Matches don't have the invite - accept / decline mechanism that I would like to have, so I implemented this part using Challanges. 

The plan is that as soon as the other player accepts and the challange gets to RUNNING state I create a match for the challange participants.

Am I going in the right direction?

Currently I have the invitation and accept / decline flow implemented, so I can get a challange to running, declined or withdrawn state, but I don't know how to create match or pending match based on a challange.

Any update on this one?


I want to implement real time multiplayer feature in my slot machine game using GameSparks SDK on Android platform. Actually, I have already implemented real-time multiplayer feature using google's sdk. It works fine if a player knows id's of other opponents(i.e. other players) to invite.

The faced challenge with google's sdk is:

If a player is interested to play the multiplayer tournament but he/she does not know any single id of player to invite the player to join the tournament then he/she will choose auto-match making option, auto-match making will fail if nobody is online at that time to join the session. Google sdk is not having baut system(i.e. Virtual opponent feature), which is very much needed for our user base.

So my question are:

1 - Does gamesparks SDK have baut feature(i.e. virtual opponent feature )?

2 - Would gamesparks SDK give 100% guarantee of successful auto-match making?

3 - If player does not know any single id to invite the opponent then how would GameSparks deal with that situation?

Please reply asap so that I can to start my development process soon.


Hi Raj,

1- You can use our Cloud Scripting component to program your own AI based on inputs from Client. Our Real-Time servers can host this logic.

2- GameSparks matches players that are looking for the same match type at the same time based on configurations you pass on. 

3- Players dont have to know about each others IDs to find a game, however if they do, then you can add them to a match using Cloud Scripting.

Hope this sheds some light,


Glad you got that covered Raj :D

Any info on the original question? 

 Hey Balazs,

Your original method of creating a pending match should work. Does your match still not exist if you manually have two string IDs in it?



Login to post a comment