Storing a Value in TinyDB - Re-opening the App And Score Is Still Visible - How to Do Please?

I create a children's game, where I want to store the score. If the child interrupts gaming and closes the app the intermediate score should be still visible in the ScoreLabel after re-opening the app. But the Reset Button should set the score label to zero.

I tried many times, but I always failed. Here is the code. Could someone please help? Thank you very much in advance. Have a great day!

this should be string text, not a variable.

Hello Kevin,

I tried, what you have suggest, but the value is still not stored. It would be great, if the value would be there, for e. g. Score: 5, if the child has clicked five times on different sprites on the canvas. But unfortunately, the value is not stored. This is the code now:

Why do you set it three times ?



Your issue is that you do not set a value (from the tinydb) to the variable global score, which will be 0 when the app starts. You are getting the tinydb value of tag Score, but not setting it to global score

tag - Score

tag - Score:

Dear Timai2, Thank you, but how would look the blogs, please? I am not so experienced. I understand, that there must be a connection between TINYDB and the "global score". But which "Set" block should I use? Could you please give an example in blogs? Thank you!


Thank you so much!

Hello Timai2, the values are counted, but not stored. There is still a mistake and it shows only a 0 after re-opening. Do you please know a solution or someone else? Thank you!

No issues here....

Dear Timai2, Thank you, but why does the value not appear, if the app is re-opened? That is the goal of these codes. I think, there is a small mistake somewhere.

Hello, Sorry, but your code is not correct. I added the button, because I had only the Sprite Touched. Now I have a working code, only the word "Score" does not appear in the Score Label. But the numerical values are alright and they also appear after re-opening the app and initializing Game-1-Screen. Here is the code, which works:

Your code is not seems to be structured, how would you going to use "Score: 5" in calculation, as here,


TinyDB work flow is as what Tim has suggested.

Sorry, but my code is correct. Your code is not correct. You are storing the "label" value as global score. Just store the number as global score, and use this to join with "Score: " in your label. As @RamNaresh says, you cannot add 1 (a number) to "Score: 0" (a string).

Hello, alright. I see that my code works and that is important. I can save a value, I see the value in the app. I can close the app, re-open it and the value is still there. However, thank you very much for your help.