How do I add values automatically when user select items that has different values each

Hi. I would like to ask. User of my future app can select any items on their screen and each item has their own specific value. How do I add all the value? I was thinking of using buttons shown below. User has to select at least 1 button from each of the 3 rows and when user press the “Total” button, the values of each button that user has choosen will add together.


I tend to use these blocks but i am not sure how to.

Besides using button, i was thinking of using List as well.

But i have problems on deciding the Blocks too.

i dont know which option is the feasible. Is there any method?

Choosing buttons would be much better. Create a stored variable and change its value everytime the user clicks the specific button. At the end, show the output of stored variable.

Can you tell me how you would calculate this?

3.0cm + 1 lane + Left

I would need to understand your math before I could tell you how to do that. Or do you just want to join the text strings like this?

3.0 cm 1 lane Left

1 Like

i would like the app to add 3.0cm + 1 lane + Left
So since 3.0cm= 1, 1 lane=1, Left=1, ( the value for each button can be seen on the Blocks)
Hence
3.0cm + 1 lane + Left
=1+1+1
=3
So when user press the “Total” Button, number 3 will appear.
Another example is user can choose button 3.5cm, 3 lane and Center.
Since 3.5cm= 2, 3 lane= 3, Center=3,
hence
3.5cm + 3 lane + Center
= 2+3+3
=8
So when user press the “Total” Button, number 8 will appear.

Okay, I think I get it now. You want to add the sum of the order of each button.

I know how to do this pretty easily in the old interface using Any Component blocks but I’m going to see if I can create a demo for you using the new drag-and-drop interface.

Edit: this feature/bug of the drag-and-drop interface makes it mathematically quite difficult to do this: Button order is reversed and should be fixed · Issue #822 · thunkable/thunkable-issues · GitHub

These blocks are ugly but they do work:

The problem is that if you don’t add the buttons to the screen in the correct order, then the math doesn’t work. I had to add them in this order:

9 8 7
6 5 4
3 2 1
10

Edit #2: @codeswept is right. Using list viewer index blocks is probably easiest.

You know you have 3 list-viewers, nd I presume only one item of each list-viewer can be clicked by the user. In this case, you can initialize three variable: centimeters, lane and direction or whatever you want. Like this: image
When List-Viewer1 is clicked, you can save the index in variable centimeters. When ListViewer2 is clicked, save the index in variable lane, and when ListViewer3 is clicked, save the index in variable direction.

Then finally, when the total button is clicked, set the text of your label(that you use to display the total) to the sum of list block. Add 3 list items in there. In the first, put the variable centimeters block, in the second, put the variable lane block, and in the third put the variable direction block.

This is all the code:

I made a sample project for you:
https://x.thunkable.com/copy/0f0a5775e759743029a86f686b267ecd

Hope this helps.
Happy Thunking!

1 Like

I cant seem to find “Component” block on my Thunkable. But I just tried @codeswept’s method and it works! Thank you nonetheless :blush:

2 Likes

Thank you for the method! it works for my app. :grinning:

1 Like

If you do need the Any Component blocks, they are in the advanced section at the very bottom of the component list in the blocks tab.

Glad it works!