Sign In Register

How can we help you today?

Start a new topic

Issue sending message to all participants of a match

I'm running into a bit of an issue when trying to send a message to all participants of a Match. Here's the overview of what I'm doing:


 1. Do an API LogEventRequest thusly:

GameSparks.Api.Requests.LogEventRequest lcer = new GameSparks.Api.Requests.LogEventRequest();
        lcer.SetDurable(true)
        .SetEventKey("playerSeat")
        .SetEventAttribute("seatNumber", seatNumber)
        .SetEventAttribute("matchID", matchID)
        .Send((response) =>
        {
            if (response.HasErrors)
            {
                Debug.Log("Error Sending action " + response.Errors.JSON);
            }
        }
       );

 2: Here's the innards of the "playerSeat" bit of cloud code (which is bound to Events > Player Seat):


var seatNumberA = Spark.getData().seatNumber;
Spark.getPlayer().setScriptData("seat", seatNumberA);
var playersToSendTo = Spark.getMultiplayer().loadMatch(Spark.getData().matchID).getParticipants();
var playerSending = Spark.getPlayer();
for (var i = 0; i<playersToSendTo.length;i++)
{
    Spark.message("playerSeat").setPlayerIds(playersToSendTo[i].getPlayer().getPlayerId()).setMessageData({"playerID":playerSending, "playerSeat":seatNumberA}).send();
};

 The intent is to send all of the participants in the match specified a JSON doc with two nodes. When I run the sequence in Unity, I get:


 

GS: SEND:{"@class":".LogEventRequest","eventKey":"playerSeat","seatNumber":1,"matchID":"58a13433d88f5d056733fc38","requestId":"d_636225322750938482_4"}

 

Which is what I'd expect. Perfect! HOWEVER, the message doesn't survive my processing. I always get:

 

Error Sending action {"message":"TypeError: Cannot call method \"getPlayer\" of undefined (event/playerSeat.js#13)"}

 

(line 13 is the inside of the for loop)

I SWEAR that this worked once, specifically the first time I tried it. But it's failed the same way every time since.




Hi Jeff,


Using var playerSending = Spark.getPlayer(); will return a SparkPlayer object. I assume you want to include the senderId in the data here ? Try using Spark.getPlayer().getPlayerId() and this should work for you. Try that and let us know if you have any further questions.


Regards,

Liam

AAAAH, yes indeed, Liam. Thanks for the assist :)

Login to post a comment