Sign In Register

How can we help you today?

Start a new topic
Answered

Question on Hearthstone tutorials's processRank module

I'm doing the Hearthstone tutorial and am stuck at the processRank module step.


I've populated all the previous code in their proper positions, but I get this error

missing ) after condition (modules/processRank.js#14)

trying to save this code as my module named "processRank"

//Retrieve the number of stars the player earned
var currentStars = Spark.getPlayer().getScriptData("stars");
//Retrieve current rank
var currentRank = Spark.getPlayer().getScriptData("rank");


if(outcome === "victory"){

    //Because the player just won, add a star
    currentStars++;
    //Save the number of stars the player has
    Spark.getPlayer().setScriptData("stars", currentStars);

    //Check for rank range
    if(currentRank >= 25 && currentRank <= 21 ){         //Check for number of stars and if they qualify a levelup         if (currentStars >= 2){
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }

    }
    else if(currentRank >= 20 && currentRank <= 16 ){         //Check for number of stars and if they qualify a levelup         if (currentStars >= 3){
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    }
    else if(currentRank >= 15 && currentRank <= 11 ){         //Check for number of stars and if they qualify a levelup         if (currentStars >= 4){
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    }
    else{

        //Don't do anything if player is rank 1 because they can't advance anymore
        if(currentRank > 1)
        {
            //Check for number of stars and if they qualify a levelup         
            if (currentStars >= 5){
                //If number is met, level up by decending down towards rank 1
                Spark.getPlayer().setScriptData("rank", currentRank - 1);
                //Reset and save the number of current stars
                Spark.getPlayer().setScriptData("stars", 0);
            }
        }
    }
}

else{

    //Does the player have stars?
    if(currentStars > 0){

    //Because the player just lost, remove a star
    currentStars--;
    //Save the number of stars the player has
    Spark.getPlayer().setScriptData("stars", currentStars);

    }

    //Check if player rank is less than 25 because that's the lowest level
    if(currentRank < 25){
        //If player has 0 stars
        if(currentStars < 1){             //Decrease level by 1             Spark.getPlayer().setScriptData("rank", currentRank + 1);             if(currentRank >= 1 && currentRank <= 9){                 Spark.getPlayer().setScriptData("stars", 5);             }             if(currentRank >= 10 && currentRank <= 14 ){                 Spark.getPlayer().setScriptData("stars", 4);             }             if(currentRank >= 15 && currentRank <= 19){                 Spark.getPlayer().setScriptData("stars", 3);             }             if(currentRank >= 20 && currentRank <= 24){
                Spark.getPlayer().setScriptData("stars", 2);
            }

        }

    }
}

 Now that's copy and pasted from the tutorials. I saw that though there were some bracket problems and I assumed that was caused by some code getting on the right side of a comment slash. So I tried getting them out and formatting it and got this

 

//Retrieve the number of stars the player earned
var currentStars = Spark.getPlayer().getScriptData("stars");
//Retrieve current rank
var currentRank = Spark.getPlayer().getScriptData("rank");


if (outcome === "victory") {

    //Because the player just won, add a star
    currentStars++;
    //Save the number of stars the player has
    Spark.getPlayer().setScriptData("stars", currentStars);

    //Check for rank range
    if (currentRank & gt; = 25 & amp; & amp; currentRank & lt; = 21) { //Check for number of stars and if they qualify a levelup
        if (currentStars & gt; = 2) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }

    } else if (currentRank & gt; = 20 & amp; & amp; currentRank & lt; = 16) { //Check for number of stars and if they qualify a levelup
        if (currentStars & gt; = 3) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else if (currentRank & gt; = 15 & amp; & amp; currentRank & lt; = 11) { //Check for number of stars and if they qualify a levelup
        if (currentStars & gt; = 4) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else {

        //Don't do anything if player is rank 1 because they can't advance anymore
        if (currentRank & gt; 1) {
            //Check for number of stars and if they qualify a levelup         
            if (currentStars & gt; = 5) {
                //If number is met, level up by decending down towards rank 1
                Spark.getPlayer().setScriptData("rank", currentRank - 1);
                //Reset and save the number of current stars
                Spark.getPlayer().setScriptData("stars", 0);
            }
        }
    }
} else {

    //Does the player have stars?
    if (currentStars & gt; 0) {

        //Because the player just lost, remove a star
        currentStars--;
        //Save the number of stars the player has
        Spark.getPlayer().setScriptData("stars", currentStars);

    }

    //Check if player rank is less than 25 because that's the lowest level
    if (currentRank & lt; 25) {
        //If player has 0 stars
        if (currentStars & lt; 1) { //Decrease level by 1
            Spark.getPlayer().setScriptData("rank", currentRank + 1);
            if (currentRank & gt; = 1 & amp; & amp; currentRank & lt; = 9) {
                Spark.getPlayer().setScriptData("stars", 5);
            }
            if (currentRank & gt; = 10 & amp; & amp; currentRank & lt; = 14) {
                Spark.getPlayer().setScriptData("stars", 4);
            }
            if (currentRank & gt; = 15 & amp; & amp; currentRank & lt; = 19) {
                Spark.getPlayer().setScriptData("stars", 3);
            }
            if (currentRank & gt; = 20 & amp; & amp; currentRank & lt; = 24) {
                Spark.getPlayer().setScriptData("stars", 2);
            }

        }

    }
}

 Now I still get the same error but I have a hunch that was needed so I just wanted to show that.

Is this a syntax problem I'm missing? What am I doing wrong?


Best Answer

Indeed, that's the issue. The operators in the tutorial are saved as HTML entities but the code snippets are output directly, thus the entities are not processed the way they should be. You can simply replace &gt; with >, &lt; with < and &amp; with &.


Here's the result:

 

//Retrieve the number of stars the player earned
var currentStars = Spark.getPlayer().getScriptData("stars");
//Retrieve current rank
var currentRank = Spark.getPlayer().getScriptData("rank");
 
 
if (outcome === "victory") {
 
    //Because the player just won, add a star
    currentStars++;
    //Save the number of stars the player has
    Spark.getPlayer().setScriptData("stars", currentStars);
 
    //Check for rank range
    if (currentRank >= 25 && currentRank <= 21) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 2) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
 
    } else if (currentRank >= 20 && currentRank <= 16) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 3) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else if (currentRank >= 15 && currentRank <= 11) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 4) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else {
 
        //Don't do anything if player is rank 1 because they can't advance anymore
        if (currentRank > 1) {
            //Check for number of stars and if they qualify a levelup         
            if (currentStars >= 5) {
                //If number is met, level up by decending down towards rank 1
                Spark.getPlayer().setScriptData("rank", currentRank - 1);
                //Reset and save the number of current stars
                Spark.getPlayer().setScriptData("stars", 0);
            }
        }
    }
} else {
 
    //Does the player have stars?
    if (currentStars > 0) {
 
        //Because the player just lost, remove a star
        currentStars--;
        //Save the number of stars the player has
        Spark.getPlayer().setScriptData("stars", currentStars);
 
    }
 
    //Check if player rank is less than 25 because that's the lowest level
    if (currentRank < 25) {
        //If player has 0 stars
        if (currentStars < 1) { //Decrease level by 1
            Spark.getPlayer().setScriptData("rank", currentRank + 1);
            if (currentRank >= 1 && currentRank <= 9) {
                Spark.getPlayer().setScriptData("stars", 5);
            }
            if (currentRank >= 10 && currentRank <= 14) {
                Spark.getPlayer().setScriptData("stars", 4);
            }
            if (currentRank >= 15 && currentRank <= 19) {
                Spark.getPlayer().setScriptData("stars", 3);
            }
            if (currentRank >= 20 && currentRank <= 24) {
                Spark.getPlayer().setScriptData("stars", 2);
            }
 
        }
 
    }
}

 


From what I've read, and I could be wrong, it looks like the way the gt and amp operators are used / defined are whats giving the errors.

Answer

Indeed, that's the issue. The operators in the tutorial are saved as HTML entities but the code snippets are output directly, thus the entities are not processed the way they should be. You can simply replace &gt; with >, &lt; with < and &amp; with &.


Here's the result:

 

//Retrieve the number of stars the player earned
var currentStars = Spark.getPlayer().getScriptData("stars");
//Retrieve current rank
var currentRank = Spark.getPlayer().getScriptData("rank");
 
 
if (outcome === "victory") {
 
    //Because the player just won, add a star
    currentStars++;
    //Save the number of stars the player has
    Spark.getPlayer().setScriptData("stars", currentStars);
 
    //Check for rank range
    if (currentRank >= 25 && currentRank <= 21) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 2) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
 
    } else if (currentRank >= 20 && currentRank <= 16) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 3) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else if (currentRank >= 15 && currentRank <= 11) { //Check for number of stars and if they qualify a levelup
        if (currentStars >= 4) {
            //If number is met, level up by decending down towards rank 1
            Spark.getPlayer().setScriptData("rank", currentRank - 1);
            //Reset and save the number of current stars
            Spark.getPlayer().setScriptData("stars", 0);
        }
    } else {
 
        //Don't do anything if player is rank 1 because they can't advance anymore
        if (currentRank > 1) {
            //Check for number of stars and if they qualify a levelup         
            if (currentStars >= 5) {
                //If number is met, level up by decending down towards rank 1
                Spark.getPlayer().setScriptData("rank", currentRank - 1);
                //Reset and save the number of current stars
                Spark.getPlayer().setScriptData("stars", 0);
            }
        }
    }
} else {
 
    //Does the player have stars?
    if (currentStars > 0) {
 
        //Because the player just lost, remove a star
        currentStars--;
        //Save the number of stars the player has
        Spark.getPlayer().setScriptData("stars", currentStars);
 
    }
 
    //Check if player rank is less than 25 because that's the lowest level
    if (currentRank < 25) {
        //If player has 0 stars
        if (currentStars < 1) { //Decrease level by 1
            Spark.getPlayer().setScriptData("rank", currentRank + 1);
            if (currentRank >= 1 && currentRank <= 9) {
                Spark.getPlayer().setScriptData("stars", 5);
            }
            if (currentRank >= 10 && currentRank <= 14) {
                Spark.getPlayer().setScriptData("stars", 4);
            }
            if (currentRank >= 15 && currentRank <= 19) {
                Spark.getPlayer().setScriptData("stars", 3);
            }
            if (currentRank >= 20 && currentRank <= 24) {
                Spark.getPlayer().setScriptData("stars", 2);
            }
 
        }
 
    }
}

 

Login to post a comment