X thunkable save score, get score from DB

i am trying to save the score then get it but its not working please can you help me.

Can you send your project link…
Do you use Firebase?

Consider shifting the block “set app bestscore to app score” to above the save block.

So that the new score is saved.

Actually with the new Thunkablex implementation, you can use the “Stored” variable type, instead of “app”. This way you just have to treat the variable as normal ones, and no need those “save” and “get” blocks

1 Like

am using phone storage

ok @Drean

thanks i try, nice i never knew about the stored variable type

If you set up the Firebase correctly, you can even safe it on the cloud, by just using the “cloud” variable type. Then your high scores can be shared with all the app instances whoever is using it. The save and get block are completely redundant. :innocent:

1 Like

can you please show me the code because trying it still not working T_T

Here… based on your blocks, I tried to replicate the flow. I would do it this way, only need one extra step to initialize the stored variable the first time and assign it with a value.

1 Like

sadly not working T_T and also tried removing the set stored bestscore to 0 because i want when the app reopens the old highest score shown.

i would love to try firebase but i have to change a lot of things and make a new screen for creating an account and logining in, it would be a hard.

The if statement to set the bestscore to zero is meant only for the first time (when the variable is “null” means it was never assigned before). The subsequent times the screen is opened, it will contain the last stored value on the phone memory. So it is essential.

Can you try one more thing? remove the “else” from the screen1 open block. and put the label block below the if statement (not within). Like this you will initialise the variable and put in value, then show it on the label.

If not, got to look at your blocks as a whole to find out what’s wrong.

the problem is its not even saving the score in game after you die the score is not saved in the highscore text

i used mit app inventor before and i am sure about the code

I migrated from MIT AI also … somethings are sequenced differently. ThunkableX made changes to accommodate iOS implementations. So I wouldn’t assume that.

Its Ok if you do not wish to show other parts of your program. You can use another label to track your “app score” variable at every juncture to find where is the problem. That is how I debug my apps to see exactly where the value was dropped.

i dont understand how to rack with another label.

i switched to firebase

still not working T_T

Ok. realtime DB blocks are also asynchronous. Meaning, depending on the speed of the internet, your realtime DB save block may not have been done before the function rungame. Since you have the Firebase set up, you can use the “cloud” type variable, and treat it just like any other variable.

If it is still not working, would you mind sharing the app for mixing so we can take a closer look?

finally i got the score but its a global score how to make each account created has his own personal high score ?