Skip to main content
Inspiring
January 19, 2017
Question

Highscore load and save problem

  • January 19, 2017
  • 1 reply
  • 472 views

I keep score with this script

package  {

   

    public class ScoreHolder {

    static public var score:Number = 0;

var sharedHigscore:SharedObject;

sharedHigscore = SharedObject.getLocal("Scoretop");

if(sharedHigscore.data.highScore == null){ //if it is being called for the first time it will be null. so change it to 0.

sharedHigscore.data.highScore = 0;

}

{

score += 1;

if(score > sharedHigscore.data.highScore){

//if score greater than highscore then set highscore = score and save it.

sharedHigscore.data.highScore = score;

sharedHigscore.flush();

}

    }

}

Code for frame

import ScoreHolder;

...............

...............

else if (aComplete)

    {

        ScoreHolder.score += 10;

        sc_1.text = ScoreHolder.score.toString();

       

        txtHighScore.text = String(sharedHigscore.data.highScore);

        gotoAndPlay(136);//LEVEL 2

    }

Score counter work perfectly but high score is not.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 19, 2017

did you save your fla and then test twice?

p.s. data.highScore will be undefined, not null, but i don't think that's the problem.

KucuKekoAuthor
Inspiring
January 19, 2017

Yes I tested and problem is not there.

kglad
Community Expert
Community Expert
January 19, 2017

so your problem is resolved?