(SOLVED) Text Fields

First Phase

I have 3 screens screens that have text fields on them. On the first two screens there is a text box on each screen where a number is automatically entered. I then would have the number that was populated on the 1st screen automatically populate one of the 3 boxes on the 3rd screen which is a subtraction problem. That is working fine. For the second box on the 3rd screen I would just get the person to enter a number and if the number they entered in the 2nd box was larger than the number in the 1st box the numbers would automatically swap and then show a result of the two numbers subtracting. That is working fine.

Second Phase

I decided to bring the number from screen 1 AND the number from screen 2 both over so the subtraction problem will have both numbers automatically and the subtract would happen automatically and the person would not have to do anything.

Problem

Both numbers are being brought over but the they have now stopped switching automatically and the subtracting has stopped. If I go back and remove the global variable that is populating the 2nd box I decided to populate it goes back working fine but the person would have to enter the second number.

Is there something I can put in place that lets the device know both boxes are populated, switch if needed and subtract? I’m thinking I have to let the event happen with the automatic populating then have some other code to tell it what to do but I’m not sure how to do that. I show the code I have now for that section.

[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 )

–code for showing bigger number first

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
numberFieldFour.text = numberFieldTwo.text - numberFieldThree.text
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

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: 13906 reply_id: 313906[/import]