Get the user input from textfield into a string variable to be accessed later

Hello, currently I am facing a problem of getting the user input from a textfield to be placed into a string variable once the user finishes typing. My end goal is to take the user input and compare it to a different string later.

My current code for user input:

function textListener( event )

    if ( event.phase == “began” ) then

        – User begins editing “defaultField”

    elseif ( event.phase == “ended” or event.phase == “submitted” ) then

        – Output resulting text from “defaultField”

        print( event.target.text )

    elseif ( event.phase == “editing” ) then

        print( event.newCharacters )

        print( event.oldText )

        print( event.startPosition )

        print( event.text )

    end

end

 --print("Here is the final text:  " ,text)

– Create text field

defaultField = native.newTextField( display.contentCenterX, 300, 190, 30 )

defaultField:addEventListener( “userInput”, textListener )

You have just copied the example code from the docs. What’s the question?

If you are wondering how to get access to the text that the user types, when they finish typing the line which reads

print( event.text )

will print their text to the console (assuming you’re in the simulator.)

Also, PLEASE use the code button when posting code!!!

You have just copied the example code from the docs. What’s the question?

If you are wondering how to get access to the text that the user types, when they finish typing the line which reads

print( event.text )

will print their text to the console (assuming you’re in the simulator.)

Also, PLEASE use the code button when posting code!!!