Sign In Register

How can we help you today?

Start a new topic

Javascript Listeners

https://docs.gamesparks.com/api-documentation/message-api/multiplayer/challengestartedmessage.html


I am trying to recieve the "challenge started" message on a javascript client to "start" the loading of the match in the client but it doesn't seem to be listed? I tried guessing around to no success.


The only other way I can think of to catch it is on the onMessage function listed in the initpreview and just make an if statement for it, problem with that is I don't know what to compare for it.


Am i approaching this completely the wrong way?


Hi d deo,


It should be the message.@class that works.


If you're having any issues with parsing the response, make sure to test the message using the Test Harness. You can see exactly what is being returned and in what format so you can more accurately parse what you need.


-Pádraig

Thanks for the reply,


Is it just

message.class?

message.@class?

message@class?

that I compare to ".ChallengeStartedMessage"...

because none of these seem to work for me.

message.summary is accessible though I guess I will use that for now.

Hi,


Yes, using the onMessage function is probably the best option for this.


You can create a switch statement that will look for the @class attribute (For example, for ChallengeStartedMessage it will be ".ChallengeStartedMessage".


For more granularity, you can inspect the contents of the message to further funnel the message to it's appropriate place, for example checking the Summary of ScriptMessages.


-Pádraig

Login to post a comment