MYPLTW 1.24 survey

I have no clue on how to get rid of this run time error whenever I vote in the survey.


That's a bit more complicated than I can bear.

Here's a simpler way to count votes.

Keep a dictionary, with keys = flavors, and corresponding values the total number of votes for that flavor. Use 0 as a default, if no one has voted for that flavor (carpet fudge) yet.

The disctionary shoud start out empty.

When some one registers a vote for a flavor, use the dictionary set and get blocks for that flavor, adding 1 to the value (0 if missing) and replacing it under that flavow.

When it comes time to rank the flavor votes, there is a dictionary block to convert a dictionary into a two column table (list of lists).

Use one of the advanced list blocks to sort the two column table by column 2 (vote count), in descending order.

The first resulting row will have the name and votes of the most popular flavor.

1 Like

Concerning the Error, somewhere along the line your code is trying to select item zero in a List. Item zero does not exist, Lists start at Item one.

your error is here


Elements is a list and not a thing, so the index is 0 (i.e. the thing has not been found in the list)

Taifun

okay thank you, do you know how i can change the flavor picker elements then?

Sorry, I did not understand what you are doing
Please elaborate

Use Do it to debug your blocks

If you want to find the index of an item in a list, then you should look for that specific item instead of a complete list

Use the companion app and Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.