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(email);
//Run query on userDetails collection
var resultOBJ = API.queryItems("userDetails", query);
var eee = resultOBJ.error();
var ccc = resultOBJ.cursor();
//If our query is successful
if(resultOBJ.error() != null)
if(resultOBJ.error() !== null)
//Get playerID which is set as the entry ID and load player
var player = Spark.loadPlayer(resultOBJ.cursor().next().getId());
When searching for userName that does not exist in the player collection,
This line... Crashes...
When trying to get error() to verify if the userName exists, error returns null
How can I know if user does not exist...
Is this line throwing an error for you? From the code you provided it looks like it's just skipping over the code contained within the 'if' since no matching record was found. Since this is the last thing in the script it will terminate once this line has been executed if the userName doesn't exist. Could you try adding some arbitrary code in after the if statement and let us know if it being reached?