Hi guys!
I’m having an error in a “text field” when I try to multiply “event.target.text” with any number.
Here is the code
local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local background local numericField\_1 local math\_1 local result = 0 local myText -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local function backgroundTap( event ) native.setKeyboardFocus( nil ) return true end local function textListener( event ) if ( event.phase == "began" ) then print( "user begins editing numericField\_1" ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then --Output resulting text from "defaultField" --print( event.target.text ) if event.target.text then math\_1 = event.target.text \* 10 -- line 40 print( math\_1 ) myText.text = math\_1 elseif ( event.target.text == "" ) then math\_1 = nil end return true elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end
And in “scene: create”
-- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen background = display.newImageRect( "images/backgroundimg.jpg", 768, 1024 ) background.x = centerX background.y = centerY sceneGroup:insert( background ) background:addEventListener( "tap", backgroundTap ) numericField\_1 = native.newTextField( centerX-65, centerY-320, 250, 60 ) numericField\_1:setTextColor( 0.8, 0.8, 0.8 ) numericField\_1.hasBackground = false --numericField\_1.text = "enter value!" numericField\_1:addEventListener( "userInput", textListener ) myText = display.newText( result, 535, 200, native.systemFont, 100 ) end
I can do the math “math_1” correctly and “myText” is replaced on screen by “math_1” but if the “textField” is empty and I touch the background, which already has a “native.setKeyboardFocus (nil)” function, the simulator gives me the following error.
lua:40 = math_1 = event.target.text * 10