In my app, I am getting two values from seperate native textboxes - one for estimated burn percentage and one for patient weight.
The problem is, if there is no value and they click the calculate button, I get an error about nil.
Here’s my code:
local Burns = 0 local Weight = 0 if (EstTextArea.text == nil) then Burns = 0 else Burns = tonumber( EstTextArea.text ) end if (WtTextArea.text == nil) then Weight = 0 else Weight = tonumber( WtTextArea.text ) end local TotalFluids = 4 \* Burns \* Weight local Fluids8 = (TotalFluids / 2) / 8 local Fluids16 = (TotalFluids / 2) / 16
I am testing whether the text is nill and if it is, setting Burns to 0 otherwise I’m setting it to the numeric value of EstTextArea.text.
I get an error that says "attempt to perform arithmetic on local Burns (a nil value)"
Shouldn’t it be setting Burns to 0 if EstTextArea.text but it doesn’t look like it is.
What am I doing wrong?