Sign In Register

How can we help you today?

Start a new topic

Mistakes in Game Data service documentation

There is a mistake on the page https://docs.gamesparks.com/tutorials/database-access-and-cloud-storage/searching-for-players-and-teams.html , under the section "Searching with Cloud Code"

After the sentence "To retrieve player details in the future, use the function below anywhere in your Cloud Code:", there is the following code:

//SEARCHING PLAYERS
//Create entry and get its data object
var API = Spark.getGameDataService();

//Create a query, in this example we want to find a user with a unique userName
var query = API.S("userName").eq("exampleName");

//Run query on userDetails collection
var resultOBJ = API.queryItems("userDetails", query);

//If our query is successful
if(resultOBJ.error() != null){
    if(resultOBJ.cursor().hasNext()){
        //Get playerID which is set as the entry ID and load player
        Spark.loadPlayer(resultOBJ.cursor().next().getId());    
    }
} else{
    //If our query comes back without results output error
    Spark.setScriptError("ERROR", "Player might not exist, please check userName again")
}
The way this code is written, it will only try to iterate through the resultOBJ if there is an error. If there is no error, it will return the error message.

The if statement should read
if(resultOBJ.error() === null){

 


Login to post a comment