[SOLVED] Help for Using Text input?

I need a some help in using Text input when using an IOS keyboard. My help is how do I make a function so if the person types in the keyboard “Good” they are correct. But if they type anything other than “Good” they are wrong. How would that function work? [import]uid: 17058 topic_id: 26871 reply_id: 326871[/import]

http://developer.anscamobile.com/reference/index/nativenewtextfield

On the ended/submitted phase check the textfield’s text using the .text property and compare the string they entered to the correct answer string. [import]uid: 84637 topic_id: 26871 reply_id: 109059[/import]

@Danny how would that work I’m getting lost doing it myself [import]uid: 17058 topic_id: 26871 reply_id: 109069[/import]

Here is a working example for you:

[code]
local defaultField – forward reference (needed for Lua closure)
local answer = “hello”
local function checkAnswer(answer, enteredAnswer)
local results = false

if string.lower(answer) == string.lower(enteredAnswer) then
results = true
end

return results
end

– TextField Listener
local function fieldHandler( event )
if ( “ended” == event.phase or “submitted” == event.phase) then
if checkAnswer(answer, event.target.text) == true then
print(“Correct Answer!”)

– Hide keyboard
native.setKeyboardFocus( nil )
else
print(“Incorrect!”)

– Hide keyboard
native.setKeyboardFocus( nil )
end
end

return true
end

– Create our Text Field
defaultField = native.newTextField( 10, 30, 180, 30 ) – passes the text field object
defaultField:addEventListener(“userInput”, fieldHandler)
[/code] [import]uid: 84637 topic_id: 26871 reply_id: 109089[/import]

@Danny thanks for the example I appreciate your help. I would of never thought of doing it that way. Thanks again

:slight_smile: [import]uid: 17058 topic_id: 26871 reply_id: 109100[/import]

Always welcome :slight_smile: [import]uid: 84637 topic_id: 26871 reply_id: 109103[/import]