Cloud Code API Functions Guide

We provide a full set of API Reference Documentation, which gives details of any of the Cloud Code API functions available in the service. These functions have been developed with you, the game developer, in mind and are designed to serve common game-play use cases you can implement using Cloud Code. However, you might have a certain game-play use case in mind, you fully expect to use Cloud Code, but you're not sure which Cloud Code API function to use. This topic identifies some common game-play use cases and is meant to help you find the Cloud Code functions which will best serve your particular needs.

Please review the following tables:

General

Use Case Requirement Cloud Code Function Summary
Access objects and functions in the GameSparks service. Spark Available to all scripts and entry point into GameSparks API.
Generate a set of unique object ids. SparkDigest Offers hash functions that return unique ids.
Access chat message attributes. ChatMessage Provides get methods for group chat messages.
Send e-mails out to your players. SendGrid Allows you to access your SendGrid account via GameSparks.
Send HTTP requests from Cloud Code. SparkHttp Gives you access to an HTTP client object.
Access parts of an HTTP response. SparkHttpResponse Provides methods for getting HTTP response attributes, such as the response headers, code, or response XML.
Generate logging. SparkLog Provides methods to record log values into the spark.log table and set the logging level.
Schedule the execution of a Cloud Code Module. SparkScheduler Allows you to specify a delay in seconds before a supplied Cloud Code Module is executed.

Players and Teams

Use Case Requirement Cloud Code Function Summary
Access player details. SparkPlayer Provides methods to get a player's details.
Send messages to your players. SparkMessage Provides methods for setting up and sending messages to players by playerId.
Update all player details collectively in one action. SparkBulkScheduler Provides access to the bulk scheduler. Also see the Using Bulk Jobs tutorial before you use this.
Access the teams in your game. SparkTeams Allows you to get a Team in your game by TeamId or by Team owner/Type.
Access the attributes of a single Team in your game. SparkTeam Provides methods to get the details of a single Team.

Leaderboards

Use Case Requirement Cloud Code Function Summary
Access your game's Leaderboards. SparkLeaderboards Provides methods for getting Leaderboards, including social and team Leaderboards.
Access Leaderboard entries. SparkLeaderboard Provides methods for getting the entries of a single Leaderboard, including a specified player's entries or a count of the Leaderboard's entries. Note that you can also use SparksRequests API to get a Leaderboard's entries - see the Accessing Leaderboard Data with Cloud Code tutorial.
Access the details of individual Leaderboard entries. SparkLeaderboardEntry Provides methods for getting the details of an entry in a Leaderboard, such as the user name or rank of the player whose entry it is.

Multiplayer

Use Case Requirement Cloud Code Function Summary
Exploit the Multiplayer capabilities of the service SparkMultiplayer Provides access to multiplayer functions, such as creating and loading Matches.
Access the details of a Challenge. SparkChallenge Includes getting Challenge run state, controlling Challenge starting/winning/drawing, consuming Challenge turns.
Access the details of a Match. SparkMatch Includes getting Match participants and adding and removing players.
Access an object that represents a player in a Pending Match. SparkMatchedPlayer Get the details of a player placed in a Pending Match, such as player location and skill level.

Cloud Data and Data Storage

Use Case Requirement Cloud Code Function Summary
Cache JavaScript objects. SparkCache Use for storing short-lived objects that are frequently accessed. This is not designed to serve as a persistent data store. Also see Using SparkCache before you use this.
Access uploaded files and downloadables. SparkFiles Allows you to access uploaded and downloadable XML and JSON files, and delete uploaded files.
Access your game's Redis instance. SparkRedis Use for storing transient data that requires fast operations. Also see the Redis Data section in the Managing Data Persistence tutorial before you use this.
Access an XML document in GameSparks storage. SparkXMLReader Gives you read only access to an XML document.

Game Data Service

Use Case Requirement Cloud Code Function Summary
Use the Game Data Service. SparkGameDataService Provides methods for working with your custom data in the Game Data Service.
Persist document state to the database. SparkDataItemPersistor Provides access to an object that can persist data to the GDS database.
Did this page help you? Please enter your feedback below.