Sign In Register

How can we help you today?

Start a new topic
Answered

Message Interception

How can i get prepared message fields on cloud code? for example i want to edit MatchFoundMessage. how can i get this match's id?


Best Answer

Hi Mark,


As messages such as the MatchFoundMessage are asynchronous, there is no debugger attached to the thread they are running on. The above, and other match related messages are the result of multiple processes. Therefore it would require both threads to have a debugger instanced and therefore run the code twice which would be undesirable behavior. Looking at your script.log I can see the log for your "Spark.getLog().debug("Simple string logging");" is logging correctly.


var myMatchId = Spark.getData().matchId; //this is the correct way to get the matchId from the message

var match = Spark.getMultiplayer().loadMatch(myMatchId); //will load the match


You aren't doing anything after this though so all you will get here is the "Spark.getLog().debug("Simple string logging");" in script.log. If you have any further questions just let me know.


Thanks,

Liam


Hi Ufuk, 


I's not possible to edit a message after it has been sent, not sure if that's what you mean ? You can edit system messages in the Message tab in the portal. For custom messages you can use a SparkMessage, you can read more about them here.


Thanks,

Liam

Hi Leam,


i meant edit message before sending it, so i use MatchFoundMessage cloud code. i found that i can get match id as;


 

var matchId = Spark.getData().matchId;

 

Hi Ufuk Coban


You can customize the messages by putting Spark.setScriptData("summary","your message here"); in the cloud code.

In the message set up you have to set the message as ${scriptData.summary}


Regards

Katie

Hi Katie,


i could not understand the last sentence. Where is this message setup screen or cloud code part?

Hi Ufuk Coban

You can write cloud code in the in user messages and global messages


The Message set up can be found in Configurator->Messages



Regards
Katie

 

Hello,


If I write code inside MatchFoundMessage cloud code it is never executed. I've put this:


 

Spark.getLog().debug("Simple string logging");    
    
var myMatchId = Spark.getData().matchId;
var match = Spark.getMultiplayer().loadMatch(myMatchId);



But neither the log is shown nor the debugger is launched when the message is thrown after a MatchmakingRequest.


What happens?


Thanks!

Answer

Hi Mark,


As messages such as the MatchFoundMessage are asynchronous, there is no debugger attached to the thread they are running on. The above, and other match related messages are the result of multiple processes. Therefore it would require both threads to have a debugger instanced and therefore run the code twice which would be undesirable behavior. Looking at your script.log I can see the log for your "Spark.getLog().debug("Simple string logging");" is logging correctly.


var myMatchId = Spark.getData().matchId; //this is the correct way to get the matchId from the message

var match = Spark.getMultiplayer().loadMatch(myMatchId); //will load the match


You aren't doing anything after this though so all you will get here is the "Spark.getLog().debug("Simple string logging");" in script.log. If you have any further questions just let me know.


Thanks,

Liam

Hi Liam,


Thanks! That clarifies all. It is a bit confusing as it seems that all scripts can be debugged.


Would be nice if we could have some "sandbox" with just one debugger to test and debug these scripts (at least to know if the execution is correct). What do you think?


Thanks again.

Best regards,

Hi Mark,


You could set the contents of a message to an object and test your code in a test script in Cloud Code to debug it and get used to how to access the various fields within the message itself, then, when confident you can transfer your code into them message script confident of it's execution. I Hope that helps.


Thanks,

Liam

Login to post a comment