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
C
Customer Support
said
over 7 years ago
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.
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.
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.
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.
a
ahsan muzaheed
said
over 6 years ago
"or some method like Spark.runtimeCollection("player"); hope someone can give an answer."
i am also looking for answer of that
Customer Support
said
over 6 years ago
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
V
Victor Tan
said
over 3 years ago
how to get online players in Cloud Code?
C
Charles Russell
said
over 3 years ago
Online status of a particular player:
Spark.loadPlayer(playerId).isOnline();
And for "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" you would use the "Player Connected" and "Player Disconnected" scripts inside the "System" folder of the Cloud Code section.
Hamlet Archer
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!
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Hamlet Archer
thanks a lot!
sam peng
Topic:
https://support.gamesparks.net/support/discussions/topics/1000059470
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.
ahsan muzaheed
"or some method like Spark.runtimeCollection("player"); hope someone can give an answer."
i am also looking for answer of that
Customer Support
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
Victor Tan
how to get online players in Cloud Code?
Charles Russell
Online status of a particular player:
And for "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" you would use the "Player Connected" and "Player Disconnected" scripts inside the "System" folder of the Cloud Code section.
-
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 2487 topics