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]