Sign In Register

How can we help you today?

Start a new topic
Answered

How to message all online players in cloud code?

hello, how would i go about sending a message to all online players? what about all players? do i get a list of all players and then loop through them, or is there a faster way? thanks!


Best Answer

Hi Hamlet,


You can achieve this by going into the Message tab in the portal and configuring a custom ScriptMessage Extention, then in cloud code use Spark.sendMessageExt method in your code to select the message you want send, you can also use the SparkScheduler to schedule when you want it to be sent.

When a player logs in you could add them to an online collection while they’re on and use this as your target for sending the online messages to. To send to everyone, you could just reference the system player collection.


Thanks,

Liam


Answer

Hi Hamlet,


You can achieve this by going into the Message tab in the portal and configuring a custom ScriptMessage Extention, then in cloud code use Spark.sendMessageExt method in your code to select the message you want send, you can also use the SparkScheduler to schedule when you want it to be sent.

When a player logs in you could add them to an online collection while they’re on and use this as your target for sending the online messages to. To send to everyone, you could just reference the system player collection.


Thanks,

Liam


1 person likes this

thanks a lot! 

Topic:

 https://support.gamesparks.net/support/discussions/topics/1000059470

Player's info would be in the runtimeCollection instead of the metaCollection. A meta collection is a read-only collection, meaning the only way to write to it would be throught the NoSQL editor in GS. It's meant to be this way as it's design is to hold persistent game data. The runtime collection can be read and written to, and that is where I assume you have your 'player' collection.


API:

https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/spark#runtimeCollection

https://docs.gamesparks.net/documentation/cloud-code-api/spark-cloud-code-api/spark#metaCollection

After i see all this. i try to use  Spark.runtimeCollection("player"); to get all the players. but i get no result.i see the player belong to system collection. is there any restrict about the player collection? or some method like  Spark.runCollection("player"); hope someone can give an answer.

"or some method like  Spark.runtimeCollection("player"); hope someone can give an answer."


i am also looking for answer of that

Hi Ashan,


You could use a bulkJob to do this. You can send these from the Test Harness or from Cloud Code. You can read more about these here. You'd need to set you playerQuery to 

"playerQuery": {"online": true} to target online players. Then set the time and the module will execute at the given time. 


Thanks,

Liam


Login to post a comment