Score Keeping in App Lab

I have a student who created an App as part of the App Design unit. We are just starting to learn about variables and they would like to go back to their app and add a score.
The app is a farming game where the user can gain or lose money as they play. We have been able to use a variable to create a monetary score. We can then modify that variable to increase or decrease on the next screen based on the user’s choices.
The problem comes once the screen changes again based on user choices. The variable doesn’t not remember the previous score and the new value is created based on the original value plus the new change.
Is there a way to “store” or remember a value from screen to screen?

Hi @kfrederick!

Welcome to the forum! It depends on where the variable was declared that determines if the changed value is remembered. There is a good video on this slide that explains scope - in fact the example that is used is a variable “points”. It is talking about functions but onEvents would act the same way. I think this will help solve your score problem but let us know if not. It is also very helpful if you provide the SHARE link to the project so we can see the code if you still have questions.

~Michelle

To go off of what @melynn said, variables only exist in their current scope. If you define a variable inside of an if statement, you’ll only be able to use it in said statement. If you define a variable as part of a function’s parameters or inside of the function itself, it can only be used in that function. Make sure you’re defining your variable outside of any statements or functions.

You may have already tackled this, too, but make sure that the text changes every time the screen changes.