Subtracting math.mins

I’m making a converter app and currently trying to convert time units. My formula includes subtracting math.mins, which returned an “attempt to perform arithmetic on a nil value” error. In addition, my time units are arranged in ascending order in a table. Here’s my formula:

result.text = tostring(tonumber(textField.text)*
				1000^(math.min(table.indexOf(timeUnits, Unit1), table.indexOf(timeUnits, "s")) - math.min(table.indexOf(timeUnits, Unit2), table.indexOf(timeUnits, "s")))*
				60^(math.max(math.min(table.indexOf(timeUnits, Unit1), table.indexOf(timeUnits, "h")), table.indexOf(timeUnits, "s")) - math.max(math.min(table.indexOf(timeUnits, Unit2), table.indexOf(timeUnits, "h")), table.indexOf(timeUnits, "s")))*
				24^(math.max(table.indexOf(timeUnits, Unit1), table.indexOf(timeUnits, "h")) - math.max(table.indexOf(timeUnits, Unit2), table.indexOf(timeUnits, "h"))))

I’m very certain that the problem lies in this part of the code.

I would start by printing out every single one of those numbers before you try this calculation, to see which one is coming up as nil.

print("a", textField.text)
print("b", table.indexOf(timeUnits, Unit1)) 
print("c", table.indexOf(timeUnits, "s")) 


result.text = tostring( calculationstuff... )

Adding a letter before will make it easy to see exactly which one it is failing on, which will allow you to debug further to work out why that is happening. It could be that the value of textField.text is “hello world” and cannot be converted to a number, or that timeUnits, "s" is returning nil.

The problem seems to be solved after I restarted Corona Simulator but thanks anyway.