I am working on an app to keep track of high scores for a number of games. the page is supposed to bring up a list picker, you then choose the game you want to add the score to, and there is a provided text box and button for adding, and a listpicker to remove.
I have heavily relied on the "Working with lists and TinyDB" Tutorial, and I have gotten it to the point at which I have officially created a procedure that generates the list and I can now add to the list and remove from it. I have 2 games that I have officially built the code for so far, and many to come once I figure this out.
The main thing I need help with is:
Upon adding the details in the socre box and hitting add score, I can see it in the delete listpicker, but it does not show on the screen.
When I close the page and reopen, the scores do not come back, even in the delete page.
You have a list of dozens of game names, and you have already set up two global variables with names picked from that list, with the need for your code to increase with the number of games.
If your code increases as your data increases, you are doing it wrong.
You must learn to work with tables (two dimensional lists of lists) .
I recommend setting up two Google Sheets:
Games, with game name in column A
Scores, with these columns
Game name (copied from the Games sheet),
Player Name
Score (Numeric)
Date (Use Numeric type and Date format)
Having 4 columns gives you grist for the mill when you want to sort and select by thos 4 columns.
@ABG Building the Spreadsheet as we speak. Is the second set going to look more like your runner tags one, where the list may duplicate the game names for each different score for the same game? Also, your original note reminded me of this:
The bug was right there, at Initialize time, in your ReadRange block inputs.
sheetName is supposed to be the piece of text with the sheet name, in your case either
or
(that's 'Game List' or 'Scores and Date'. I have a terrible memory.)
But what did you have instead of that? Global variables meant to hold lists, initially empty.
What does an empty list look like in text?
[]
That's what AI2 blithely accepted as the sheet name and asked for in its API call for the Range Request.
When you fix this, for good measure, remove spaces from the sheet names using the Sheets interface's tab pulldowns. Having spaces in identifiers is asking for trouble.
@ABG I am sorry to be a pest. I changed the names of the sheets to Games and Scores respectively and updated the block to reflect the sheet names and the errors went away.
An unrelated question. Can you teach me or point me at a resource or tell me how I can pull the Game names from the game spreadsheet into a List Picker?
It seems that in your marathon tutorial you just plugged the options in via CSV, and it sounds like this is common. I would prefer to keep them on my own list and I think you suggested as much originally. I cant seem to find any real tutorials for this.
Trying to figure out pulling from CSV was like ramming my head into a wall repeatedly. So I caved and I put 50 different games in a pull from CSV list line and that worked. I have pulled together the major parts of the app and the submitted scores are now showing in my google sheet! That being said, The listview is only showing the games line. So with that, I have a few final questions:
How do I get all of the columns to show up in the listview? or do I need multiple Listviews for a google sheets program like this?
The system is just taking the most recent score and putting it at the end. Is there a way to create a sort button or have the system autosort after a score is added?
Currently, once the score is added, I have a reset that removes any elections in the Listpicker, but it clears everything, including the hint, is there a way to reset it to the hint?
Another page of my app has multiple listviews separated by a small horizontal arraingement, because I cant't seem to find a way to set a proper space between components. The system won't let some of the lists put all the data on the screen at a time, and instead give me a scrolling list. Is there a way to fix that? Only asking this one because I hope its a simple fix, elsewise 1 and 2 are the most important.
You can make things simpler in the app by asking Sheets to filter its range download to include only the scores for the game selected in your game list picker:
(example copied from my Marathon sample, you must change names.)
The returnData contains the three column table of scores just for this game.
Before you rush to display all scores, you can sort the returnData in descending order by score, and just use its first row (with maximum score) to populate three Labels.
You don't need that ListView, if all you want is highest score.
P.S. If you are in love with that ListView, you can repurpose it to show the filtered and sorted scores for the currently selected game. Since the game name shows in the List Picker .Text, all you need show in the ListView Elements are score and date from columns 2 and 3 in the sorted and filtered scores table. You already have code like that, but not exactly.
Since I think I would like to see my scores for a game over time, I probably will go for the filtered and sorted scores in listview for the currently selected game.
I have the blocks created, but I need to understand how you would put this all together. Do I need to remove the Read range tag? or would I just have the Read filter after the listpicker selection is made?
For the got filter result, am I copying the full code with component adjustments from the marathon example, or is it simplified?
And then for the sorted list bit, is that part of the filter result block, or where does that go?
To say I am a newbie is an understatement, I have appreciated your help so much.
Actually, I think I figured most of it out from your combined comments. Information is displaying as individual games and dates. I rebuilt the got filter result using about half the information from the got range result box.
Now I really only need help knowing how to implement the sorting. I have it right after GetData, but the only game with 2 scores reads me the riot act: "Bad Arguments to >, the operation cannt accept the arguments: , ["57,600"], ["78,650"]
How did commas get into your numbers?
Go upstream into your Sheet and switch the formatting of the scores column to numeric with no commas.
AI2 math does not understand commas nor forgive them.