setText doesn't stay with text after clicking again

Hello guys, so I’m making a sort of clicking function in a game and I save the score with local storage but it re startsthe numbers when I click again, for example if I have a number that is 32 and I click again it’s gonna be 1

Can you share the wick file?

My Project12-9-2021_22-39-44.wick (146.8 KB)

So i got it to make the project save your progress but their a bug and I forgot how to fix it ;-;

here the project
My Project12-9-2021_19-58-13.wick (146.9 KB)

it just adds 1’s

Yeah, I fix but I forgot to post the updated one

lovecounter.lovetxt.setText(localStorage.getItem(‘love’))
The line above sets lovetxt to the saved data from “love”
which the line project.love+=1 from chicken replaces everything on lovetxt to project.love

project.love=localStorage.getItem('love')
The line above sets project.love to the saved data which can be incremented from the line project.love+=1 from chicken.
Now, the last problem is the output will be something like 1111 that’s because localStorage only stores strings not integers.
So for example, when you run console.log("11" + 12), the output will be 1112 that’s because "11" is a string and 12 is an integer. 12 Cannot be incremented
So when you store integers onlocalStorage, it will automatically be converted to strings, so we have to convert the strings to integers.

project.love=parseInt(localStorage.getItem('love'))

You noticed the function parseInt(), that function converts strings into integers which can now be incremented
Now it will work as you originally intended

Here’s the wick file: My Project12-11-2021_15-23-08.wick (147.3 KB)

1 Like

Thank you so much for the help!