Lots of Trouble With native.newTextField

I am pulling my hair out over this one… I hope it is something simple, and i’m just being an idiot about it.

FYI, Corona SDK 2010.243

I am implementing a high score function that asks for user input (a name, in this case) to be added to the high score table if their score is high enough.

I have the logic in place to do the following:
-Check if the User score is good enough to make it on the High Score board. If this score is high enough, display an input box and keyboard, and allow the player to type.
-run a addHighScore(*Player Name*, *Player’s Score*) function, that works when passed actual strings/values
Now, when I hit ‘Return’ on the keyboard, it minimizes, and it continues to show the Game Results screen, as intended. However, it is not executing the function to add the high score with the new inputted name.

When I touch elsewhere on the screen than the input box, the keyboard stays on screen, which is currently intentional. (if I understand my own code correctly.)

can anybody give me a hand? Code samples are below.

My expected functionality is this:
1.Show ‘Game Results Screen’ with the User’s score.
2. If the score is high enough, prompt for user input (name), and then when the user has hit ‘Return’, add the high score with the addHighScore Function.
3. When the user has submitted the high score by hitting “Return”, minimize the keyboard, and hide/remove the text box.
Any help is appreciated!

Input Field Handler

 local function fieldHandler( event )  
   
 if ( "began" == event.phase ) then  
 -- This is the "keyboard has appeared" event  
 -- In some cases you may want to adjust the interface when the keyboard appears.  
 print "Keyboard Spawned!"  
  
 elseif ( "ended" == event.phase ) then  
 -- This event is called when the user stops editing a field: for example, when they touch a different field  
 -- Hide keyboard  
  
 elseif ( "submitted" == event.phase ) then  
 -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard  
 -- Hide keyboard  
 native.setKeyboardFocus( nil )  
 enteredName = defaultField.text  
 defaultField:removeSelf()  
 defaultField = nil;  
 print "Submit Keyboard!"  
 print("Collected name is:"..defaultField.text)  
 addHighScore( enteredName , score)  
  
  
 end  
   
 end  
  

get user input Function

[code] function getUserInput( prompt, inputType )

msg = display.newText( prompt , 0, 280, “Verdana-Bold”, 12 )
msg.x = display.contentWidth / 2 – center title
msg.y = 60
msg:setTextColor( 255,255,255 )

local inputFontSize = 18
local inputFontHeight = 30

localGroup:insert(msg)

defaultField = native.newTextField( 10, 60, 280, 30, fieldHandler )
defaultField.font = native.newFont( native.systemFontBold, inputFontSize )
defaultField.x = display.contentWidth / 2
defaultField.y = 60
defaultField.text = “Name”
–defaultField.inputType = “text” --inputType --text?

native.setKeyboardFocus( defaultField )

return entertedName
end
[/code]

Check if High Score/Create input Box
Please keep in mind that in the below example, when running on the Corona Simulator, it works. (High Score board shows “FakeName” and the Score.) So it seems that just in my Text Field code, i’m not getting love.

Also, if the name passed to addHighScore is a nil, the function should substitute ‘Guest’.

[code] if( isHighScore( score ) ) then
print “High Score!”
print( system.getInfo( “environment” ) )
if ( system.getInfo( “environment” ) ~= “simulator” ) then
print “Not on Simulator, proceed with Keyboard”
getUserInput(“Please enter your name:”, “text”)
end

if ( system.getInfo( “environment” ) == “simulator” ) then
print “Simulator Detected, Passing Junk Name”
addHighScore(“FakeName”, score )
end

end
[/code] [import]uid: 13801 topic_id: 6645 reply_id: 306645[/import]

Side note, can I just say how absolutely frustrating it is to not be able to run this in the actual simulator?! Good grief, i’m sure thats where 90% of the stress is coming from. I can run it to the xCode Simulator, but it still doesn’t work there, and I have no good code to check it against because the Provided Native Keyboard 2 Sample code doesn’t collect, or do anything with the text you can input!

Okay… Deep Breath… *Rant Over.*

Thanks for your patience. [import]uid: 13801 topic_id: 6645 reply_id: 23144[/import]

Does anybody have any input box sample code they wouldn’t mind posting? If I could just get some sample code that collects the text from the box, that would get me going in the right direction.

Thanks in advance for any help! [import]uid: 13801 topic_id: 6645 reply_id: 23490[/import]

Hi BlueDuck, I noticed that in your code, you’re nil’ing the defaultField variable before you print its text value… so the print probably doesn’t work because defaultField is already gone:

defaultField = nil; print "Submit Keyboard!" print("Collected name is:"..defaultField.text) [import]uid: 10284 topic_id: 6645 reply_id: 26893[/import]