Saving highscore

Good Afternoon,

Running into an issue where I can't seem to save the high score value into the TinyDB cause of a list error:

What I'm trying to achieve
This screen will be used for the player to save their Name, Score and Date & time.
This information will then be retrieved on another screen in a list view where players can see all highscores if the player chooses to save their score for others to see.

2 Likes

Bonjour,

L erreur vient peut-être que vous sauvegardiez les données à l index 1 du fichier csv.

Votre index 1 correspond peut-être aux titre de vos colonnes du fichier csv.

Essayer avec index 2

2 Likes

That did not resolve the issue.
Thanks for giving me something to try.

@ABG I followed your guide and I'm a little lost as to why I'm running into this error.

The Highscore starts on the question page, then is saved to a tinydb

Then we go to the next screen where the user input's their name and a timestamp is generated

image

But when I go to save the score I get this error

image

Blocks

1 Like

Anyone? I've been trying to figure this out for hours and this is really holding up my progress.

I'm not sure what's causing your problem; your blocks look fine to me. Anyways, you should only allow the user to save the highscore if it's greater than the current highscore.

1 Like

The player should be able to save their score at the end of each game. No matter if they have the high score or not

Seems here

image

is the problem.

Is global high_score a list of lists ?

2 Likes

@TIMAI2

This explains the flow of the data.

  1. Original values start on questions screen

  2. We then continue the process on the save screen
    image

This is the AIA file if you wish to explore the code base. Trivial_Pursuite_bacup.aia (21.7 KB)

1 Like

This is the tutorial I followed but I'm not getting the same outcome.

Im gettiny very desperate. I need to have this functional in the next 10 to 12 hours I'm getting really really desperate.

Im going to get some rest. Any ideas while im sleeping would be a great help. Plese review the code, do some testing and I'll check it out in the morning.

Cheers, Rod

I think (haven't checked it) that the bug is in the initialization of high_score.
On first run, you should add an entry and save it to the TinyDB.
Something like: (psedue code)
screen initialize:
high_score = get-from-tinydb
if (empty(high_score) {
add-to-list (high_score) the item: make-list (0,someone,current_date)
save-to-tinydb
}

There are other options to solve your bug, like asking if the list is empty inside the add-high-score procedure, and act differently in case it is empty (First user).
If it's empty, you just add the new entry to the list, else, "your current code".
(in other words, you are accessing index 1 in the while test condition, while the list is empty...)
I think this one is better.

Hope this helps,
Eran.

Here is an updated copy of my high score app with score, name, and datetime.

Data entry consists of score and name.
Date and Time come from Clock1, at time of entry.

Note the last entry was for score 15, filed in the middle.
The datetime format can be changed to shorten the lines, per taste.

global variables:

This is a constant tag in TinyDB where the actual high scores list is kept.


This is the Add button. It calls a procedure add_a_hi_score with the score and player name. (datetime is taken from the Clock, so it is not needed as a parameter.) After updating the high scores, we retrieve them using a value procedure highScores, show them in CSV form, and reset the Score textbox.


This value procedure gets the high scores list from TinyDB.
If it is not there or is not a list, a fresh list with a stopper is returned.


This value procedure returns a stopper for the high scores list, with a 3 item list:

  • 0 points (I hope no one ever submits a negative score!)
  • a challenge for a name
  • today() for starters


Date formatting is concentrated here, so it can be customized all in one place. I took the lazy way out.


A local copy of the high scores list is taken using the retrieval procedure listed above.
When the proper insertion point is found, a new 3 item list is inserted there, and the high score list is rewritten into TinyDB.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme
for a demo.

max_score_dated.aia (2.9 KB)

Blocks Overview:

3 Likes

Thank you so much for taking the time to put this together.
I've got it set up exactly like you've shown me and it's working.

Now time to see if I can move this across screens into a list view

I've got the list passing into the next screen where all the high scores are displayed but not having much luck on getting it into the list view. Any tips?

The list view doesn't accept list to csv list block

Displaying a table nicely:

http://puravidaapps.com/table.php

1 Like

Will I also have the option to delete entries from the Database since there should be an option to also remove an entry from the tinyDB

Yes, if you can get the index into the highScores list. A SelectionIndex is a good way.
Don't forget to immediately save the highScores list after removing a list item.

Updating sample ...

1 Like

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