Why is my variable resetting everytime?

Hello, I continued working on my Brick Breaker game today and ran into a problem. I can't figure out why my app resets the coins every time I play the game. All the coins I get in a game are saved in the coins variable but every time I go back to my coin variable in my store it is reset to 0 and only the coins from a single game are saved. My file is below :D'
LG Justin
retroGames (1).aia (1.1 MB)

1 Like

you have to store your data in TinyDB...
and read the stored data from TinyDB while starting the app...

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles
How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

block11wwsd

When your screen init. you need to put down this block ↓


and this block every time you update your variable↓.

Did any of these help @Justus3106 ? Or fix the problem?

Yeah sure, thank you very much for the answers :slightly_smiling_face:
It fixed my problem, I had somehow already suspected that the variable must be updated

1 Like

Thank you, I will look through the tutorial @Taifun

Also @Justus3106 , use Mobile CSP. It's an ap level programming course done through App inventor. Registration is free, and you have access to all the material/references you need. Plus the community too...
https://course.mobilecsp.org/mobilecsp

Thank you, I will check it out

1 Like

So, I'm really sorry that I said it would work because it worked in my test file. However, it still doesn't work in my actual app. I have now changed the code and added the two variables in the shop screen first, which still doesn't work. I want to sum up my CoinsOfGame variable with my coins variable, so that the total coins in the coins variable are added together. But it is still the same problem. If I play a game and get e.g. 30 coins and then go to my shop screen, because the game is over, the total coins are 30. But if I start a new game with the back button on my screen and win with e.g. 20 coins and then go to the store screen, the total coins are 20 and not 50 although the coins of both games should be added. Here is my updated game retroGames (2).aia (1.1 MB)
I don't know what I have done wrong, I can't comprehend why it isn't working

1 Like

You have to learn to use screens. From what I can see, you open a new screen every time. You are not using the close screen block. All the screens you open are open even though you cannot see them.

Small changes:

retroGames2.aia (1.1 MB)

1 Like

Thank you very much <3 This really helped me!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.