Help with updating the sum of selected options in multiple lists

Hi everyone, I can't seem to figure out this out. How do I make it so that if a user selects a different list option.. the sum of the values will be updated correctly instead of it accumulating.


When I first select these two options (Nasi Lemak (494 Cal) and Bak Ku Teh (324)) it equates to 818 calories. But if say I change the second option (Bak Ku Teh to Chicken Porridge (181 Cal) instead of 494 + 181.. it accumulates 494 + 324 + 181. How do I make it that it rolls back the value of the option is changed?


These are the code blocks to my two ListPickers. The total calories are updated in the set totalcalories block. Please help

You could store the food items and their calorie values in a dictionary.
The code to add the calories would go like this:

Edit: Changed ListPicker.Text to ListPicker.Selection


Thanks! I do have some questions if using your method, how does it know which food calories it needs to choose to add up? And how it's different than my method?

You could make a dictionary, like this:

Make sure to remove the other information; you could add that on a separate label (which I've named "AboutFood"):

You're just using a lot of redundant code. You could shorten it up with an Any Component block, but using Dictionaries is way easier.

1 Like

Okay but now it returns false as the total calories value:


Appreciate your help!

A boolean? I don't think that's supposed to happen :laughing:
I'll try and see what's wrong.

Can you try setting "totalcalories.Text" to only this (below)?