Hi , I am using Local Storage of the browser to keep track of highest score. But it seems if I generate a build lets say Build -Link-1 and score highest score as 10 . browser will store highestScore key with value 10. And If I generate another build say Build-Link-2 . Even though we don’t score any points it shows highest score as 10 of the previous build link since it stores in origin as https://playcanv.as . I feel its strange and want to have highest score for particular build as well.
code which I used is below
var GameScoreManager = pc.createScript('gameScoreManager');
GameScoreManager.attributes.add('scoreEntity', { type: 'entity' });
GameScoreManager.prototype.initialize = function () {
this.scoreCount = 0;
this.highestScore = 0;
this.scoreElement = this.scoreEntity.element;
this.app.on("update-score", this.updateScore, this);
if (!localStorage.getItem("highestScore")) {
localStorage.setItem("highestScore", this.highestScore);
console.log('Highest score set successfully ')
}
this.highestScore = parseInt(localStorage.getItem("highestScore"));
this.once('destroy', () => {
this.app.off("update-score", this.updateScore, this);
});
};
GameScoreManager.prototype.updateScore = function () {
this.scoreCount++;
if (this.scoreCount > this.highestScore) {
this.highestScore = this.scoreCount;
localStorage.setItem("highestScore", this.highestScore)
}
this.scoreElement.text = this.scoreCount.toString();
this.app.fire("score-updated", this.scoreCount);
};
GameScoreManager.prototype.getCurrentScore = function () {
return this.scoreCount;
}