I’m using global variables to pull numbers from one screen to my current screen. Once the numbers are pulled they perform a subtraction problem in an new.TextField. The problem is that the numbers are ALWAYS pulled but sometimes it performs the subtraction problem and sometimes it doesn’t.
If I touch in one of the boxes where a number was pulled and then tap back to the screen it performs the subtraction problem. It’s like sometimes it needs a notification that the numbers have been pulled. What am I doing wrong?
[lua]local function onnumberFieldTwo( event )
if ( “ended” == event.phase ) or ( “submitted” == event.phase ) then
native.setKeyboardFocus( numberFieldThree )
numberFieldFour.text = numberFieldTwo.text - numberFieldThree.text
end
end
local function onnumberFieldThree( event )
if ( “ended” == event.phase ) or ( “submitted” == event.phase ) then
native.setKeyboardFocus( nil )
end
end
numberFieldTwo = native.newTextField( 120, 45, 85, tHeight, onnumberFieldTwo )
numberFieldTwo.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldTwo.inputType = “number”
numberFieldTwo.text = _G.numberOne
numberFieldThree = native.newTextField( 120, 100, 85, tHeight, onnumberFieldThree )
numberFieldThree.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldThree.inputType = “number”
numberFieldThree.text = _G.numberEight
numberFieldFour = native.newTextField( 120, 165, 85, tHeight, onnumberFieldFour )
numberFieldFour.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldFour.inputType = “number”
– Add fields to our new group
–code for showing bigger number first
local function togglevalues()
if isSimulator or numberFieldThree.text == nil or numberFieldTwo.text == nil then return true end
if tonumber(numberFieldThree.text) > tonumber(numberFieldTwo.text) then
local temp = numberFieldTwo.text
numberFieldTwo.text = numberFieldThree.text
numberFieldThree.text = temp
numberFieldFour.text = numberFieldTwo.text - numberFieldThree.text
end
end
togglevalues()
localGroup:insert(numberFieldTwo)
localGroup:insert(numberFieldThree)
localGroup:insert(numberFieldFour)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua] [import]uid: 72372 topic_id: 13997 reply_id: 313997[/import]