Using Bulk Operations to Send Global Messages to Players

The GameSparks platform allows you to perform bulk operations. In this tutorial, we’ll use bulk operations to send every player on our platform a message. There are two ways to do this:

Sending Global Messages through the Request

Here, we use a ScheduleBulkJobAdminRequest to send a global message to players through the Test Harness:


{
 "@class": ".ScheduleBulkJobAdminRequest",
 "playerQuery": {},
 "scheduledTime": "2016-03-29T10:16Z",
 "script": "var msg = Spark.message(null); msg.setPlayerIds([Spark.getPlayer().getPlayerId()]); msg.setMessageData({\"message\":\"good day!\"}); msg.send();"
}

You'll need to set three fields:

Note that in this example:

Using a Module in the Request

Another way to use the ScheduleBulkJobAdminRequest to send a global message to your players is to execute a module by referring to its Short Code:


{
 "@class": ".ScheduleBulkJobAdminRequest",
 "moduleShortCode": "messageModule",
 "playerQuery": {},
 "scheduledTime": "2016-03-29T10:32Z"
}

In this example, when the request is executed, every player will be sent the message set in the module.

Using Modules? Modules allow you to create your own libraries of JavaScript that can be included within other scripts. For more details see the Modules section in Cloud Code

Sending Global Messages through Cloud Code

You can send a bulk job request in Cloud Code in two ways:

Building Bulk Job via Request Builder


var bulkJobRequest = new SparkRequests.ScheduleBulkJobAdminRequest();

//If using module
bulkJobRequest.moduleShortCode = "messageModule";

//If using script
bulkJobRequest.script = "var msg = Spark.message(null); msg.setPlayerIds([Spark.getPlayer().getPlayerId()]); msg.setMessageData({\"message\":\"good day!\"}); msg.send();"

bulkJobRequest.scheduledTime = "2016-03-29T10:32Z";

bulkJobRequest.playerQuery = {};

bulkJobRequest.Send();


Sending Bulk Job via Spark.sendRequest


Spark.sendRequest({"@class": ".ScheduleBulkJobAdminRequest",
 "playerQuery": {},
 "scheduledTime": "2016-03-29T10:16Z",
 "script": "var msg = Spark.message(null); msg.setPlayerIds([Spark.getPlayer().getPlayerId()]); msg.setMessageData({\"message\":\"good day!\"}); msg.send();"


Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here