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
C
Customer Support
said
over 2 years ago
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.
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
S
Strider Agostinelli
said
over 1 year ago
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.
Customer Support
said
over 1 year ago
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.
Vince Jewlal
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?
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Strider Agostinelli
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.
Customer Support
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
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2346 topics