Listpicker sublist not saving

Thanks in advance for the help!

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:

  1. 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.

  2. When I close the page and reopen, the scores do not come back, even in the delete page.


You are on a road to disaster.

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.

Sample Tutorial:

To learn more about Lists:

@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:

All your Base

1 Like

I have several Sheets in the Marathon sample.

Look at the Arrivals sheet to see how to collect player scores at the detailed level.

Here is the start of my code:

I have a long way to go, but I could use some guidance. I am getting the following error message when I try to open the score page of the app:



Is this an issue with the pathway from the app to sheets? or is there something wrong with the range details and how I am pulling the information?

Post the URL for the sheet so we can examine its contents.

Also, be sure to start your sheets with a header row. That Read Range block might need one.

Game List - Google Sheets

I was not allowed to read your sheet.
Go into the Share link in your sheet, and request a publicly readable link and post that instead.

@abg Game List - Google Sheets

I failed to read your code closely enough.
image

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
image

or
image

(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.

A sample of loading a table from a Media folder CSV file.

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:

  1. 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?

  2. 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?

  3. 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?

  4. 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:


component_event
(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.

Here is an appropriate sort list block to use:



where scores was loaded from returnData.

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.

Yes, it is better to let the Sheet do the work of filtering upstream, to reduce the amount of data arriving from the Web.

So no to Read Range, yes to ReadWithExactFilter on the game name.

You already know how to extract columns 2 and 4 (date and score) to fill a ListView if you want to see scores for one game over time.

If you export and post your .aia without the .json file for security, I can show you the blocks.

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"]

Here is the code as is for now:

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.

That fixed it! Thanks!

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