Ask coding questions

← Back to all posts
How to add a save system for the game
NingHao (0)

I took days to code this game but I think if there is a save system it will be better. So can someone help me please?

Answered by xfinnbar (149) [earned 5 cycles]
View Answer
xfinnbar (149)

Use localstorage! Example:

localstorage.setItem("clicks", 100) // sets 100 as the value of clicks

localstorage.getItem("clicks) // returns 100
NingHao (0)

@xfinnbar thanks!! I will go to try now

NingHao (0)

@xfinnbar but where should i put the code?

xfinnbar (149)

Anywhere you run this code, it will save. Put the getItem at the start of the game to load in your save, and put the setItem in either your onclick add a save button. @NingHao