Sign In Register

How can we help you today?

Start a new topic
Answered

global vs user messages

there seem to be the same events for each; when an event fires, how does it decide who to send it to?  ChallangeStartedMessage -> fires global message, and then fires user message foreach user?  is the user version private?


Best Answer

Hi Vince,


The main difference is that you can access the current player using Spark.getPlayer() in a user message but you can't access the current player in a global message Cloud Code script. If you have any further questions just let me know.


Thanks,

Liam


Answer

Hi Vince,


The main difference is that you can access the current player using Spark.getPlayer() in a user message but you can't access the current player in a global message Cloud Code script. If you have any further questions just let me know.


Thanks,

Liam

Is it possible to subscribe to both a global and a user message?  For instance in Global->ChallengeStartedMessage I want to run the Cloud Code to set up the challenge and assign the shared data.  This would contain things like both player's health.  

However, in User->ChallengeStartedMessage I want to send private data that only that user would see.  This would be things such as the player's hand.



Hi Strider,


Yes, in fact this is how these scripts function out of the box. When a message is triggered; first the Global Message script is executed (without player context), after which the corresponding User Message script is executed once for each player receiving the message, in the context of that player. 


So if you were to add some player-specific script data to the message in the Player Message script (e.g. Spark.setScriptData({"myHand": Spark.getPlayer().getScriptData("hand")}), the data added to the message will be specific to the player receiving it.


Regards,

Vinnie

Login to post a comment