On the corona simulator, everything works well without an error code. When testing on the android devices available to me (google nexus 7, version 4.2) the adb terminal reads, “Lua Runtime Error: lua_pcall failed with status: 2, error message is: /Users/Name/Desktop/App/main.lua:3678: attempt to perform arithmetic on a nil value”
The task is to do a simple addition calculation. When the user enters “01+1”
and
[lua]
local leftOperand
local operator
local rightOperand
leftOperand, operator, rightOperand = string.match( selfImput1.text, “(%d+%.?%d?%d?)(%+)(%d+%.?%d?%d?)”)
print ("left operand equals "…leftOperand) – terminal shows “01”
print ("right operand equals "…rightOperand) – terminal shows “1”
print ("userInput.text before adding left and right operand equals "… userInput.text)
print (tonumber(leftOperand) + tonumber(rightOperand)) – terminal shows “2”
userInput.text = tonumber(leftOperand) + tonumber(rightOperand) – this line doesn’t work on the device
print ( userInput.text) – terminal shows “01+1”
userInput.text = string.format("%.2f", math.round(tonumber(userInput.text)*100)/100) – terminal shows this line to have an error [/lua]
For some reason it seems when I add the two operands together on the device, I can’t get the userInput.text to become the new value. When I try tonumber(userInput.text = tonumber(leftOperand)…
corona simulator tells me that there is an unexpected symbol near “=”.
My mac is 10.6.8
My corona version is 2012.971 (2012.11.15)
I tried downloading the most recent corona but I need 10.7 on my mac, so I reverted back to a previous version of corona I had downloaded.
Thanks for the help and I appreciate any thoughts or ideas!