I’m trying to develop an app similar to that of a shopping list, except the user chooses from existing items (restaurant menu items). This data is up on the airtable and that is working fine. The problem I’m having is in showing the selected items in a list. Here is an image of how I want it to be set up:
My current issue is that I can get it to show one item in the list, but as soon as I click another it just erases that item and replaces it with the new selected item. Below is are my blocks for this:
If it’s any help, following this I will want to be able to pull numeric data from these list items - the data contains the product name and the number of carbs in the item. I will then need to use some maths to calculate these carbs. Just in case this makes a difference to how I approach this?
Thanks, everybody!
Edit: The search function isn’t supposed to be doing anything just yet, that’s a problem for another time!
You’ll need to create another list which you store (as a variable for example) and when a user selects an item you add it to that list. I think you want something like this:
If you post more screenshots, someone can probably help you figure out why it isn’t working. Did you try the code @Steven posted as is (e.g. in a separate screen or project)? Did that work?
As you can see in the above video, the items that I click are not populating the list below at all… Ideally when I click one item it will show, then another click will show a second item below and so on if that makes sense?
Hmm, so if the code looks correct, where do I go from here? Thank you for taking a look, I really appreciate it! If needs be let me know if you want the link to the project!
There are other factors that can affect correct code blocks. As a somewhat extreme example, if you were running an endless loop (e.g. forever block) that was constantly changing/retrieving data within the same screen, that might be enough to take up all of the device memory allocated to Thunkable and prevent other blocks from working properly.
So taking a look at your project would be helpful as well.
But I’ll still set up a similar project to see if it works as you have it set up in your latest screenshot.
I suspect there is something else going on in the project which is preventing it from working as expected. @tatiang is correct, looking at the project is likely the easiest way to help you. If you don’t want to share it publicly you can send it to me in a private message and I’ll take a look.
As a side note, the light green blocks (error, column, item, & index in this case) are values that are being returned from the block they are attached to (GetColumn or ItemClick) which means that they will only work inside the do or then do blocks immediately below them. It is possible that this is contributing to the issue as there can be weird behavior if you try to use those blocks outside of their scope.
You’re using app selectedList as the columnName input for your spreadsheet but it doesn’t look like you’re giving it a value (besides the invalid item block). Try setting the columnName to a text string, as I’ve done in my example.
I’m actually surprised you’re able to pull any data into the top list viewer using the item block!
Thanks for this info, weird that it isn’t working on mine! I don’t have a forever block as far as I’m aware - if you’d like to look at the project is it best to paste a link publicly here? I’m totally new to all of this as you can probably guess! The app selectedList is so that it presents data from the right airtable column - here’s the blocks from the previous screen (seen in the video) which includes the likes of McDonalds, TGI Fridays and Greggs:
Okay, that makes more sense. Again, initializing a variable to “item” doesn’t do anything and should probably be avoided. But now I see where you are assigning item to the app selectedList variable and that looks fine.
Sharing a link publicly as a non-pro user is really up to you. It does draw attention to your project so if you’re keeping things under wraps, you might not want to. Ultimately, the project is available to the public whether or not you choose to post a link.
As @Steven said, you can always send him/us a private message with a link since we’re offering to help you.
I just noticed that you are initializing app selectedList on the item select screen. I would delete that entire block and see if it fixes things. If not, then seeing your project would give me a big-picture view of how you’ve organized things.
Edit: see my response below – you may not need to delete that block after all.
Better yet… you’re assigning an item (text string) to a list variable. What you really need is a separate variable called app columnName (or similar) that stores the item on the previous screen. Then, use that variable for the column value when you call Get Column. And initialize app selectedList to empty list on the item select screen.
I honestly have no idea if telling the compiler to do nothing and to simultaneously do something when an item is clicked can cause problems but I’d definitely rule it out by deleting the blank blocks.
Thanks for taking a look, do you know which variables to get rid of then? It’s kind of hard for me to visualise these things - found most help through videos and images to be honest so I have some confidence in my adjustments!
Are you suggesting I change this variable to a new one
and then insert that variable into the column name on the next screen?
I’ve got rid of the conflicting blocks now too - thanks for the heads up, it wasn’t the cause as the issue remains but definitely good practice for future!
Yes! Exactly. What you’ve done isn’t technically wrong (except for initializing app selectedList again on the Item_Search_Screen, which you should not do if you’re using it to store the item that was clicked on in the RESTAURANT_SCREEN) but it’s confusing and it ends up being a problem when you want to use app selectedList as a list later.
As an explanation, you’ve assigned a text string such as “McDonalds” to a variable that has no specific type – you initialized it as item but that has no value yet on the RESTAURANT_SCREEN – and then later you try to use it as a list when you add items to it on the Item_Search_Screen.
So what I’m suggesting is that you need two variables: one to hold the column value (in the screenshot above, replace set app selectedList to item with set app columnName to item); and then a second variable called app selectedList, initialized as an empty list on the Item_Select_Screen – and be sure to delete all instances of it from the RESTAURANT_SCREEN.
Programming languages typically require that you maintain a variable’s type throughout the code. So if at one point you create a variable that is an integer and then you set that value to “hello”, the compiler doesn’t know how to treat that and either returns an error or does nothing. This is in essence what you’ve done by adding a list item on the Item_Select_Screen to what was already created as a text string variable on the RESTAURANT_SCREEN.
And just an aside: only initialize a particular variable once in your entire project. If you need to change it’s value, use the set variable block instead of the initialize variable block.