Sign In Register

How can we help you today?

Start a new topic
Answered

I can't see the second participants

I create the match with bot and i add bot to the match in cloud code like this:

 

var matchId = Spark.getData().matchId;
var matchData = Spark.getMultiplayer().loadMatch(matchId);
var participants = matchData.getParticipants();
if(participants.length == 1){
    matchData.addPlayersById("5a0add2795b16304fd4fc89d");
    participants = matchData.getParticipants();
}

But i don't see second participant (my bot) in matchMaking response. How i can add bot to match that i see my second participant (bot) ? 


Thanks in advance.


Vitaly


Best Answer

Hi Vitaly,


You could add the bot to your match and return the match participants in the UserMatchFoundMessage with the following:


var matchId = Spark.getData().matchId;

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

var participantsData = matchData.getParticipants();

if(participantsData.length == 1)

{

    matchData.addPlayersById("Your Bots PlayerId");

    participantsData = matchData.getParticipants();

}


//Set and Get the matchData with the following

matchData.setMatchData({"participants":participantsData});

matchData.getMatchData(participantsData);


Does this solution look like it would work for you?


Thanks,

Ronan





Hi Vitaly,


At the point in which the MatchMaking Response runs, the response has already been formulated. You can append to it, but you can't directly change it. 


Adding a bot to the match in the response will successfully add them to the match, but it won't be seen in the response.


You can add extra scriptData to be returned with the response, indicating that you've added a bot player for instance.


-Pádraig

Do you mean something similar like this?


matchData.setMatchData({"participants":participantsData});

 


Thanks in advance.


Vitaly

Answer

Hi Vitaly,


You could add the bot to your match and return the match participants in the UserMatchFoundMessage with the following:


var matchId = Spark.getData().matchId;

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

var participantsData = matchData.getParticipants();

if(participantsData.length == 1)

{

    matchData.addPlayersById("Your Bots PlayerId");

    participantsData = matchData.getParticipants();

}


//Set and Get the matchData with the following

matchData.setMatchData({"participants":participantsData});

matchData.getMatchData(participantsData);


Does this solution look like it would work for you?


Thanks,

Ronan




Hi Ronan. 


Yes, thank you for your help.

Vitaly

Login to post a comment