Sign In Register

How can we help you today?

Start a new topic
Answered

GS, PUN and Canceling of Matches

Hi GS community,


I am trying to achieve a proper MatchMaking flow using GS and PUN.


My game lets 2 players compete against each other in realtime


GS should take care of player data and Matchmaking as it's much more versatile


PUN should take care of gameplay mechanics, synchronized objects etc.


My current approach is:


- Use GS to get 2 players to Match

- using the MatchID, I create a room in PUN

and load the level.


This works perfectly. However what I don't really understand is what happens if a player leaves the match, e.g. he exits the game by going back to Main Menu. What should happen is that the Match is "Destroyed" and the game ends Immediately.


I found no function to "cancel" an existing match once the 2 players are matched, and I feel I'm missing something here. It's a bit confusing to get started with GS with Sessions and Challenges, so help would be greatly appreciated!


Best Answer

Hi Alex,


You should be able to use SparkMatches removePlayersById to remove players from the match. For a drop in drop out match you could just send the same MatchMakingRequest that was used to match the players again with the action field set to "cancel" to remove them from that ongoing match. Try that and if you have any further questions just let me know.


Regards,

Liam


Answer

Hi Alex,


You should be able to use SparkMatches removePlayersById to remove players from the match. For a drop in drop out match you could just send the same MatchMakingRequest that was used to match the players again with the action field set to "cancel" to remove them from that ongoing match. Try that and if you have any further questions just let me know.


Regards,

Liam

I'm having trouble getting the SparkMatch Instance


 

var matchId = Spark.getData().MATCH_ID;

var matchInstance = Spark.systemCollection("matchInstance");
var query = { "_id": matchId };

var matchId = matchInstance.find(query);

if(matchId.count() == 0){
   Spark.setScriptError("error", "UNKNOWNID")
   Spark.exit()
}

var match = Spark.getMultiplayer().loadMatch(matchId);

if (match == null) {
   Spark.setScriptError("error", "MATCH_NOT_VALID")
   Spark.exit()
}

var playerId = Spark.getPlayer().getPlayerId();

//This triggers an MatchUpdateMessage which is then received by the other player
match.removePlayersById(playerId);

 

This line:



 

var match = Spark.getMultiplayer().loadMatch(matchId);

 returns null even though the matchId is valid?


Could you point me in the direction of what I'm doing wrong?


Thank you!



 

Solved, made coding error with the matchId variable (too tired)

 

Login to post a comment