Using Text Boxes for a game like Hangman

Posted this in newbie questions but thought it might get a bit more response in this section. Im just wondering whether someone could point me in the right direction for tutorials or just some sample coding.

Ive done bits and bats of Java Programming but Lua seems a little bit more complex as in it requires more code to do 1 action.

Heres a general idea of what im trying to do in my best attempt at coding:

        local AnswerBox = native.newTextBox() // I know this isnt right ive found a little bit of a tutorial on setting this up, Just wondering if this is the code I would be using for the answer box.

        

        if AnswerBox = (“ketchup”)

        then

        display.TextBox(“Complete”)

        else

        display.TextBox(“Incorrect”)

        end

Any help would be greatly appreciated please.

Thanks, Matt.

I’ve hidden your other post since it’s a duplicate.

You should get comfortable with learning how to use the display.newText() API call.  It has an attribute called .text that you can use to change the text.  In other words you need one display.newText() object to handle your Correct/Incorrect answer and change it’s value using it’s .text:

response = display.newText("", 0, 0, native.systemFont, 32)

response.text = “Correct”

The native.newTextField() also has a .text method where you can retrieve what the player typed in.

Thanks for your response mate, Currently looking into it, Which would you say would be easier to code the choice of text boxes or dragging letters into place to spell a word?

Dragging letters is pretty darn easy.  You wouldn’t have to drag them either.  Just touch them and have them jump in to place.

Ill give that a shot :slight_smile: Do you have a link to any tutorials that will cover any parts of it mate? Id use LearningCorona but about 60% of the tutorials are dead links. Also is there any of sites for Corona tuts?

Thanks.

Ok so heres what ive managed to get so far:     

   local Answer = native.newTextField(0,0,\_W-0.8,48);                  Answer.inputType = "default";                  local Font = "HelveticaNeue" or system.nativeFont;         Answer.font = native.newFont(font,24);                           local hintText = "Answer Here";         Answer.text = hintText;                  Answer.align = "center";                  Answer.x = 250         Answer.y = 750                      function background:tap(e)             native.setKeyboardfocus(nil);             end                      function Answer:userInput(e)             if (e.phase == "begin") then             elseif (e.phase == "editing") then             elseif (e.phase == "ended") then             elseif (e.phase == "submitted") then             elseif (e.target.text == "ketchup")             then Answer.scene = "level1screen"             else             end  

Could anyone shed a little light on how I would edit the last bit around so it would display a simple box or image to say Correct or Incorrect once the right or wrong answer has been input.

Thanks.

Maybe there is a better way to do it but I would say make a box and put it on top of everything else but make it invisible, then expse a function to pass the desired text of successful or unsucessful attempt to play and make this box visible.

Hope this helps.

Hmm, I think I understand what you mean, Make a simple text box and a Continue button underneath it, Once the correct words have been placed into the text box the Continue button appears? If so, I think ill give that a shot :slight_smile:

For example:

if e.target.text = “ketchup”

then make button visible

else

make button invisible?

As far as tutorials go, we have a bunch here:   http://www.coronalabs.com/resources/tutorials/

And Jamie at TandG apps has a bunch on his website (basically he took the working stuff from learning corona since that site isn’t being maintained).   I think his url is:  http://tandgapps.co.uk

His site seems to be down at the moment, so you might want to check back later.

Thanks Rob, Will take a look tonight :slight_smile:

I’ve hidden your other post since it’s a duplicate.

You should get comfortable with learning how to use the display.newText() API call.  It has an attribute called .text that you can use to change the text.  In other words you need one display.newText() object to handle your Correct/Incorrect answer and change it’s value using it’s .text:

response = display.newText("", 0, 0, native.systemFont, 32)

response.text = “Correct”

The native.newTextField() also has a .text method where you can retrieve what the player typed in.

Thanks for your response mate, Currently looking into it, Which would you say would be easier to code the choice of text boxes or dragging letters into place to spell a word?

Dragging letters is pretty darn easy.  You wouldn’t have to drag them either.  Just touch them and have them jump in to place.

Ill give that a shot :slight_smile: Do you have a link to any tutorials that will cover any parts of it mate? Id use LearningCorona but about 60% of the tutorials are dead links. Also is there any of sites for Corona tuts?

Thanks.

Ok so heres what ive managed to get so far:     

   local Answer = native.newTextField(0,0,\_W-0.8,48);                  Answer.inputType = "default";                  local Font = "HelveticaNeue" or system.nativeFont;         Answer.font = native.newFont(font,24);                           local hintText = "Answer Here";         Answer.text = hintText;                  Answer.align = "center";                  Answer.x = 250         Answer.y = 750                      function background:tap(e)             native.setKeyboardfocus(nil);             end                      function Answer:userInput(e)             if (e.phase == "begin") then             elseif (e.phase == "editing") then             elseif (e.phase == "ended") then             elseif (e.phase == "submitted") then             elseif (e.target.text == "ketchup")             then Answer.scene = "level1screen"             else             end  

Could anyone shed a little light on how I would edit the last bit around so it would display a simple box or image to say Correct or Incorrect once the right or wrong answer has been input.

Thanks.

Maybe there is a better way to do it but I would say make a box and put it on top of everything else but make it invisible, then expse a function to pass the desired text of successful or unsucessful attempt to play and make this box visible.

Hope this helps.

Hmm, I think I understand what you mean, Make a simple text box and a Continue button underneath it, Once the correct words have been placed into the text box the Continue button appears? If so, I think ill give that a shot :slight_smile:

For example:

if e.target.text = “ketchup”

then make button visible

else

make button invisible?

As far as tutorials go, we have a bunch here:   http://www.coronalabs.com/resources/tutorials/

And Jamie at TandG apps has a bunch on his website (basically he took the working stuff from learning corona since that site isn’t being maintained).   I think his url is:  http://tandgapps.co.uk

His site seems to be down at the moment, so you might want to check back later.

Thanks Rob, Will take a look tonight :slight_smile: