I have built a simple calculator, using a text field, function, and button. When you enter a number, it adds five and returns a result.
Thats fine. If you enter nothing in the text box, you get a runtime error, as Im assuming, arithmetic is attempting to be performed on a empty field, or nothing, and nothing qualifies as a string, which returns an error.
How could I go about getting around this? Im sure I should be doing something about the text in red highlighted below.
Thanks,
local widget = require( “widget” )
result = display.newText(“Result”, 240, 125, 250, 100, native.systemFont, 20)
result:setFillColor(1,1,1)
field1 = native.newTextField( 150, 150, 180, 40 )
field1.inputType = “number”
field1.size = 16
field1.text = “1”
field1.align = “center”
local calc = 5;
local function firstfield( event )
if ( event.phase == “began” ) then
result.text = (field1.text + calc)
end
end
local visit = widget.newButton
{
defaultFile = “button.png”,
label = “Display”,
fontSize = 24,
width = 120,
height =40,
labelColor =
{
default = { 1, 1, 1 },
},
emboss = true,
onPress = firstfield,
}
visit.x = 150; visit.y = 225