Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by peepli

Hello,

I want to implement localStorage for one of my values in my Achievements class. So basically what this class does is take player data from backend database and if a player clears certain tasks an achievement gets unlocked. For now I have just 1 achievement defined as follows

Achievements:{
1:{name:'First_Achievement',status:1}
},

The status field acts like a flag for my achievements. If status is 1 then achievement is still locked and if it goes 0 the achievement gets unlocked.

This is a skeleton code for when my achievement gets unlocked. This block of code is checked in my game every 10 seconds to see if a certain task is cleared to unlock an achievement

checkAchievements:function(){
this.probsSolved = this.getTeamProbSolved();
if( this.Achievements[1].status == 1 && this.probsSolved.length >= 3 ){
this.triggerAchievements(1); //spawn achievement notification
this.Achievements[achID].status = 0;
}
},

So this works fine when I run the game. The "this.Achievements[achID].status" is set to 0 throughout the game until I start my game again the next time. It sets the "this.Achievements[1].status" back to 1 and the if loop runs again and spawns the achievement again which I don't want because its obvious I want my achievement to be spawned or displayed just once and not everytime I run the game.

So how do go about an implement localStorage here? I suppose I need to store my "Achievements.status" flag in the localStorage so that the if loop runs just once and not everytime. Or is there any other way I can implement this?

I have not done localStorage before so I do not know how it works. A skeleton code or any libraries I can use would be appreciated a lot. Thanks!

1 decade ago by stillen

This should help you out:
http://impactjs.com/forums/code/localstorage-plugin

This sets up local storage in a nice easy to use impact wrapper and goes through some use cases in the posts.

1 decade ago by peepli

Quote from stillen
This should help you out:
http://impactjs.com/forums/code/localstorage-plugin

This sets up local storage in a nice easy to use impact wrapper and goes through some use cases in the posts.


PERFECT!

Thanks a lot stillen
Page 1 of 1
« first « previous next › last »