Sign In Register

How can we help you today?

Start a new topic

String to Number CloudCode

I can't get the correct way to get my ScriptData("division") into var division.

var thisChallenge = Spark.getChallenge(;
var challengerId = thisChallenge.getChallengerId();
var expired = thisChallenge.getScriptData("Expired");
var challengedPlayer = thisChallenge.getChallengedPlayerIds();
var division = Spark.getPlayer(challengedPlayer).getScriptData("division");
var newDivision = parseInt(division);

if (expired == "true") {
    var request = new SparkRequests.LogEventRequest();
    request.eventKey = "postScore";
    request.score = -50;
    request.division = newDivision;


 I've tryed 

request.division = Spark.getPlayer(challengedPlayer).getScriptData("division");



var newDivision = Number(division);

 Nothing works, if I set manually


request.division = 1;

 It Works well...

My ScriptData is already a number so it should work with Spark()
 has it does here on PlayerConnectedMessage


var playerID = Spark.getPlayer().getPlayerId();
var displayName = Spark.getPlayer().getDisplayName();

if(Spark.getPlayer().getScriptData("Registered")=== null) {
    Spark.getPlayer().setSegmentValue("league", "bronze");
    Spark.getPlayer().setScriptData("division", 1)
    Spark.getPlayer().setScriptData("score", 1000)
    var request = new SparkRequests.LogEventRequest();

    request.eventKey = "postScore";
    request.score = Spark.getPlayer().getScriptData("score");
    request.division = Spark.getPlayer().getScriptData("division");

        "playerID" : playerID,
        "displayName" : displayName,
        "userName" : Spark.getPlayer().getUserName(),
        "segments": Spark.getPlayer().getSegmentValue("league")
    Spark.getPlayer().setScriptData("Registered", true);

if(Spark.getPlayer().getScriptData("Registered"=== true)){
    //Do returning user stuff


I had to loadPlayer and not, getPlayer ...

request.division = Spark.loadPlayer(challengedPlayer).getScriptData("division");

 Sorry for new Topic.

Hi Flavio, 

No problem. Glad to see you figured it out. If you have any other questions just let us know.



Login to post a comment