Hello, I'm a beginner in MITT and I was developing a molar mass calculator. I have two problems (that have appeared so far):
When I put "H20" in the formula, this error appears: "The * operation cannot accept arguments: , [""], [true]"
When I put only "H", this appears: "Select item from list: Attempting to get item number 2 from a list of length 1: ["H"]"
I would be extremely grateful if you could shed some light on my errors, below are the blocks, I thank you in advance.
Comparing two constants will always return a constant true/false result, so don't even bother.
You don't need to make separate variables for every Element name.
This should be done as a table, with Element names in column 1 and their atomic weights in column2, to take advantage of the AI2 list block Lookup In Pairs.
You can use Google Sheets to type this up quickly, and then download it as a CSV (Comma Separated Values) file, to upload into the Media Folder for a runtime load at app startup.
That would reduce your block count by a factor of at least 20.
How are you putting H20 into your formula? You don't seem to have a variable of that name.
'H' is an item in your List 'Listaelementos'. The error message however is saying you are trying to get a non-existent item from a List. If 'FormulaList' is supposed to be a List, it should be initalised with a "create empty list" Block, not a text Block.
This code will break up your formula into a list, the first step in calculating a weight.
You need to add a pass that will insert a default 1 for elements lacking a number.
Oh, I just realized, my splitter did not take into account atom counts greater that 9, and would separate digits into list items. Those would need to be combined, in the same pass where I recombine multiletter atom names.
After you fix that, do another pass backwards from the end to index 2, looking for either pairs of atom names followed by a number, or solitary atom names.
Use a running total, and apply your lookup and multiplication to get a number to add to the running total.