prevent the user from going to the next scene without input text

I would like to have the user input text before s/he can progress to the next scene.

I’ve been able to accomplish this previously with check mark boxes. But I can’t seem to figure it out with input text boxes.

Here is what I have tried thus far (resulting in many errors).

 local mainGroup = display.newGroup() myText = display.newText( "Enter your full name", 500, 350, native.systemFont, 38 ) nameField = native.newTextField( 500, 400, 320, 36 ) nameField.inputType = "name" nameField:setReturnKey( "done" ) nameField.isVisible = true myText.isVisible = true local function onTextInput( event ) local userInput(event) = event.target if switch.isOn == true then score = score + 1 elseif switch.isOn == false then score = score - 1 end mainGroup:insert(nameField) mainGroup:insert(myText)

I’m trying to assign a value (or score) of 1. If that value is there the user can pass.

Looking at my own code I know it’s wrong but I have no clue how to fix this?

Surely you want to check the value of what they have typed in. I assume the default value of the input box is “”, just an empty string, but a string nonetheless. Check that they have entered something which involves actual letter and/or numbers and you’re done.

@rich,

Thanks for formatting the code.  Please be sure however to give it extra love and make it legible, well formatted.  Every little bit of extra effort you put in to make your question more easily digested and read helps you in the end.

Note: You should also really start using locals.  I see your code contains a bunch of globals and this will be a problem for you in the future.

@horacebury is right.  This is as easy as checking the value of nameField.text and not enabling a button or some other such action till the value meets your standards.

local mainGroup = display.newGroup() -- A flag I made up for this example to gate changing scenes local canChangeScene = false -- Just pass group as first argument local myText = display.newText( mainGroup, "Enter your full name", 500, 350, native.systemFont, 38 ) local function userInput( self, event ) -- Did the user input text and is it at least one character long? canChangeScene = ( event.text and string.len(event.text \> 0 ) ) end local nameField = native.newTextField( 500, 400, 320, 36 ) mainGroup:insert(nameField) nameField.userInput = userInput nameField:addEventListener( "userInput" ) -- WRONG: Not a valid type from this list: https://docs.coronalabs.com/api/type/TextField/inputType.html#keyboard-types -- nameField.inputType = "name" -- ?????? I don't think you need this -- nameField:setReturnKey( "done" ) --- Now later, you can refer to 'canChangeScene' and if it is false don't allow the scene to change

Download this file (just updated): https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Look at example 14.  (it is a bit elaborate, but complete in the sense that it shows a couple of variations on this concept.  So I hope it will get you well started).

Look for the word GATE in the scene files (found in ifc/ folder)

This is example 14:

https://www.youtube.com/watch?v=hsDiGvAFsZY&feature=youtu.be

1 Like

Note: I’m done for the day and won’t be answering further on this thread.  So don’t feel I’m ignoring you if you post additional details here.

However, the prior answers have everything you need.

Surely you want to check the value of what they have typed in. I assume the default value of the input box is “”, just an empty string, but a string nonetheless. Check that they have entered something which involves actual letter and/or numbers and you’re done.

@rich,

Thanks for formatting the code.  Please be sure however to give it extra love and make it legible, well formatted.  Every little bit of extra effort you put in to make your question more easily digested and read helps you in the end.

Note: You should also really start using locals.  I see your code contains a bunch of globals and this will be a problem for you in the future.

@horacebury is right.  This is as easy as checking the value of nameField.text and not enabling a button or some other such action till the value meets your standards.

local mainGroup = display.newGroup() -- A flag I made up for this example to gate changing scenes local canChangeScene = false -- Just pass group as first argument local myText = display.newText( mainGroup, "Enter your full name", 500, 350, native.systemFont, 38 ) local function userInput( self, event ) -- Did the user input text and is it at least one character long? canChangeScene = ( event.text and string.len(event.text \> 0 ) ) end local nameField = native.newTextField( 500, 400, 320, 36 ) mainGroup:insert(nameField) nameField.userInput = userInput nameField:addEventListener( "userInput" ) -- WRONG: Not a valid type from this list: https://docs.coronalabs.com/api/type/TextField/inputType.html#keyboard-types -- nameField.inputType = "name" -- ?????? I don't think you need this -- nameField:setReturnKey( "done" ) --- Now later, you can refer to 'canChangeScene' and if it is false don't allow the scene to change

Download this file (just updated): https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

Look at example 14.  (it is a bit elaborate, but complete in the sense that it shows a couple of variations on this concept.  So I hope it will get you well started).

Look for the word GATE in the scene files (found in ifc/ folder)

This is example 14:

https://www.youtube.com/watch?v=hsDiGvAFsZY&feature=youtu.be

Note: I’m done for the day and won’t be answering further on this thread.  So don’t feel I’m ignoring you if you post additional details here.

However, the prior answers have everything you need.