Hello, I just wanted to post this real quick for anyone who may be looking for this. I was looking all over the place for tutorials for how to use Tinydb to store highscores and all i found were huge pages of lessons and some unexplained procedures etc. All mainly shown in AI1 as well.
Well, for anyone new who is just starting to learn App Inventor...let me save you some headaches with Highscores for your game.
For one single highscore on one single screen.... this is literally ALL you need to make it work.
Now let me explain. First off... Screen1 is a copy/paste version from my working program thats why you see the red flag. I just wanted to isolate just what you need to know.
1- create a procedure and name it.
2- find the label you use to post your final score at the end of your game. Mine is FinalScoreValueLabel.
3- where you see FinalScore > HighScoreLabel.....I created a high score page in my options. The highscore is that label.
So basically that entire if loop says: if the score i just got in the game is higher then what ever my current highest score ever is, then make my game score the new high score. Obviously if its not higher then it will not do anything,
*I keep all the names close togather so it may look a bit confusing, but the purple box that says: call HighScore.store value is not the highscore label....this is my Tinydb renamed to HighScore.
4-within your Tinydb drawer, select this block i have in the pic. the: call Tinydb.StoreValue block In the tag, that was written on the spot, this is where you define the name of the tag to be stored on your phone. I named mine HighestScore
ValueToStore: this is the highscoreLabel.text --- from my highscore page in my options. The same one from the if loop.
Basically, if my score of the game is higher then the highest score, it changes to the new score otherwise it does nothing. but weither the high score changed or not, the program keeps what ever the Highest score is..stored.
At the bottom of the pic is the single call procedure to call this entire thing, You need to slot this in where ever your function that results in the game being over is.
Finally, the screen initialize block:
5- you need to call the highestscore tag that is saved on your phone when the screen first starts up. This is the call Tinydb.getvalue. block
I used this particular GetValue box for a reason: The tag is obviously calling the name you saved it under on your phone from earlier. But the other item....valueTagNotThere.....this needs to be set so that the very first time you load up your phone, there will obviously be nothing stored on your phone yet, but as we all know...computers need absolutely everything spelled out for them. Without this tag, the computer will try to find a saved item that does not exsist yet. Remember....the highestScore Procedure does not run until the program is already running, you finished a game and got a score. So this GetValueBox in Screen Initialize will read waaaaay before you ever get to actually storing your first score. So this is a very important step. You NEED to define a value for when theres nothing to look up for the first time.
My explaining is way more work then building the actual blocks :) I know there are alot of tutorials about Tinydb, but like i said. I wanted to spell it out in my own words for new comers. And for AI2. There is no need to jump right to all the big stuff first shot like storeing 10 items on 3 different screens etc.
Understand whats happening first....then you wont need to look up a tutorials for the complex stuff when you get to it,,,, babysteps.
Hope it helps!