Spark.getData() retrieves the data associated with the request, including the attributes passed in from the SDK. Since the data is an object, you can easily retain the data inside it through a variable name.

getPlayer().setScriptData(name,value) will save a value under a specific name in the scriptData object which can easily be accessed and is viewable in any response that returns the player's data - for example the AccountDetailsRequest.

Alternative? Optionally, you can use setPrivateData() to store the data in the player's privateData, which is not present with any response unless called for and returned specifically. For more information, see Storing Custom Player Data.

5. To call this request from the SDK and pass in the values, you can use the Event Key to reference the correct Event ShortCode.

The Basic Method! This example using a combination of Events and Cloud Code illustrates the basic method of passing and returning values from SDK to the GameSparks platform.

Android Requests and Responses Extra Functionality

GameSparks conveniently offers you the ability to augment existing calls and responses with extra functionality. In the portal, navigate to Configurator > Cloud Code. In the Scripts panel, you'll see sections for Requests, Responses, User Messages, and Global Messages. Once expanded, you can use these sections to add Cloud Code to any request, response, or message and achieve the extra functionality you want in your game.

In this tutorial, we'll follow an example of how to do this by adding Cloud Code to the Registration request and response so that:

The RegistrationRequest will be blocked if the email is not passed in.

The RegistrationResponse will get the registered player's email and save it against that player's scriptData.

Lastly, we'll see how to add scriptData to requests from the SDK for Android clients.

Registration Request

First, we'll navigate to Configurator > Cloud Code > Requests and open the Cloud Code Editor for the RegistrationRequest. In there we'll add:

After the response is received, the player will be authenticated, so calling Spark.getPlayer() will return the just registered player. After getting the player, we save the email value against their scriptData.

SDK Request

Finally, here's how we add scriptData to your requests from the SDK, similar to the way we use Attributes for Events: