Sign In Register

How can we help you today?

Start a new topic
Answered

How to Withdraw from Matchmaking? (Unity)

We're using the new matchmaking system and can have up to 4 players connect to the lobby.


A client currently initiates the matchmaking process by:

    new MatchmakingRequest().SetMatchGroup("group1").SetMatchShortCode("MULTI_MCH").SetSkill(1).Send((response) =>

    {

      if (response.HasErrors)

      {

        Debug.LogError(response.Errors.JSON);

      }

      else

      {

        Debug.Log(_username + " requested matchmaking succesfully!");

      }

    });


And due to MatchUpdatedMessage and MatchFoundMessage, gets updated when new people join the matchmaking.

However I haven't been able to figure out how to get people to leave matchmaking , or disconnect from the match. I had thought it was from step 7. on here: https://docs.gamesparks.net/tutorials/how-to-match-players. However this says: 


"This will cancel a MatchmakingRequest that has not yet received any Match message."


And indeed using:

  public void WithdrawFromMatchmaking()

  {

    new MatchmakingRequest().SetAction("cancel").SetMatchShortCode("MULTI_MCH").Send((response) => {

      if (response.HasErrors)

      {

        Debug.LogError(response.Errors.JSON);

      }

      else

      {

        Debug.Log(_username + " cancelled matchmaking succesfully!");

      }

    });

    ChangeMenu("LoginMenu");

  }


It doesn't seem to do anything after the player has already been connected.


Thanks!





Best Answer
Hey Jesse,

Check out the SparkMatch api [https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/sparkmatch#removePlayers]...

This allows you to remove players from a match. You could create a LogEventRequest, which takes the playerId and mathId as attributes, and then calls 'removePlayers' which will remove that player from the match. In the call-back of that request you could check to see if the current player is still a participant, if you want to double-check.

Hope that helps,
Sean

 

1 Comment

Answer
Hey Jesse,

Check out the SparkMatch api [https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/sparkmatch#removePlayers]...

This allows you to remove players from a match. You could create a LogEventRequest, which takes the playerId and mathId as attributes, and then calls 'removePlayers' which will remove that player from the match. In the call-back of that request you could check to see if the current player is still a participant, if you want to double-check.

Hope that helps,
Sean

 

Login to post a comment