Skip to first unread message
Message has been deleted

Italo

unread,
Apr 18, 2017, 11:50:03 AM4/18/17
to MIT App Inventor Forum
In your HideWord procedure, you need to leave the first and last letters unmasked by "_".
You can check with an IF to see if letter = 1 or letter = lenght(global HiddenWord) to leave those letter unmasked.
Why you go to a second screen to get the word to guess?
If the letter introduced is in the word, then you have to do a FOR EACH thru global Word and find out where that letter is (position) and replace in the hiddenWord the "_" for that letter.

SteveJG

unread,
Apr 18, 2017, 11:52:23 AM4/18/17
to mitappinv...@googlegroups.com
perhaps show the word in a Label to display?

Things to think about:

How is the user imputing his word choices?   You probably need a TextBox.     

You are changing screens...how are you passing information from screen to screen?    You can avoid that problem by using a single screen ... here is how:  

We want you to have fun with App Inventor and learn to program.  Here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Ethan Schafer

unread,
Apr 18, 2017, 11:55:46 AM4/18/17
to MIT App Inventor Forum

The second screen is for a second player to enter the word, it just looks like this: 

Ethan Schafer

unread,
Apr 18, 2017, 12:06:07 PM4/18/17
to MIT App Inventor Forum
Didn't you make a Hangman App before Italo? Where can I find it, and what did you do to solve this?

Italo

unread,
Apr 18, 2017, 12:48:55 PM4/18/17
to MIT App Inventor Forum
Yes I did. But it was back in 2015. I made things a little over complicated in it, that's why I didn't use it as an example in your case.
It was in the Classic App Inventor Gallery. I published it in the AI2 Gallery now. Here's the link.

I did what I wrote in my previous post. I used a FOR EACH loop to go thru the unmasked word to find the position of the guessed letter. When I find the letter, I replaced the "_" in the masked word, in the same position, with the letter in that position in the unmasked word.

Basically:
You have 2 words:

Unmasked: COMPUTER
Masked: C_ _ _ _ _ _ R

Letter guessed : "P"

Using a FOR EACH loop, you find that "P" is in the 4th place in the unmasked word, so go and replace the 4th character in the masked word with a letter "P".

Result: C _ _ P _ _ _ R


Ethan Schafer

unread,
Apr 20, 2017, 11:23:20 AM4/20/17
to MIT App Inventor Forum
I've spent hours trying to figure out what you mean and I just can't quite wrap my head around it... sorry, I'm new to coding. Would you mind building the block segment for me to look at?

Ethan Schafer

unread,
Apr 24, 2017, 11:00:44 AM4/24/17
to MIT App Inventor Forum
bump

Taifun

unread,
Apr 24, 2017, 12:33:50 PM4/24/17
to MIT App Inventor Forum
you might want to try something based on Italo's answer and if you get stuck, post a screenshot of your relevant blocks

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  
How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the
 Top 5 Tips: How to learn  App Inventor

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by  Taifun.         



Italo

unread,
Apr 24, 2017, 4:08:21 PM4/24/17
to MIT App Inventor Forum
I was going to say what Steve said. We are here to help you, not to do it for you. And we do this, not because we are bad people. We do it because this way you will learn how to solve problems by yourself.
You said you tried for hours, so show us what you tried and what it does and we can tell you what is wrong with it.
Also, evaluate yourself and decide if you are not trying to do stuff more advanced than your current App Inventor proficiency. If that's the case, please keep learning basic stuff, like the links Steve posted. 

Ethan Schafer

unread,
Apr 25, 2017, 11:41:03 AM4/25/17
to MIT App Inventor Forum
Here's what we got so far. The problem that I'm having is that when the letter is plugged into the word, it reveals all the letters before it and gets rid of the underscores.


Italo

unread,
Apr 25, 2017, 1:12:31 PM4/25/17
to MIT App Inventor Forum
Why are you calling the procedure HideWord when the guessButton is pressed? Shouldn't be the evaluateLetter procedure called instead?
Also, you are calling the evaluateLetter procedure from inside the HideWord procedure, which I don't think makes a lot of sense. We don't need to mix the procedures.
You should have one procedure to create the masked word, and a different one to evaluate the letter typed and replace that _ for that letter in case it matches.

To populate the global Word, use the WHEN OTHER SCREEN CLOSED and use "result" as the word.


In the other screen, use this block to pass the word to Screen1:




In the evaluateLetter procedure you should have a FOR EACH like you do, and go from 1 to the length of the word to guess. You call that "position". That's good.
If you have spaces between the "_", you need to remove those before. Use the REPLACE ALL block for that and replace " " for "".
Then you have to compare with an IF the letter in the "position" being evaluated is = to the letter guessed.
If it is, you have to replace ONLY that _ with the letter. What you are doing is using a REPLACE ALL block which does with says: Replaces ALL occurrences of "_", not just one.
To do that, you need to do a little trick:

Split the masked word in two parts with the SEGMENT block and put them in two different variables: 

First part is from
START 1
LENGTH current position - (minus) 1

Second part is from
START current position + 1
LENGTH (length of the masked word - (minus) length of the first part we separated before) - (minus) 1

That will leave the _ in the current position out. Which is the position of the letter guessed.

Next use the JOIN block to join the first part + the letter guessed + the second part.

That is the masked word now which will shows the letter guessed. 

If you are using spaces between the _ then you need to create a procedure to add the spaces back before showing the masked word in your label.


Ethan Schafer

unread,
Apr 26, 2017, 1:22:52 PM4/26/17
to MIT App Inventor Forum

Hey Italo, thanks for the response. I've been trying to figure out what you're saying and I think I've done it, but I'm getting Runtime Errors now. 

Italo

unread,
Apr 26, 2017, 1:29:09 PM4/26/17
to MIT App Inventor Forum
What errors? If you didn't understand something, let me know what was it and I'll try to be clearer.

Ethan Schafer

unread,
Apr 26, 2017, 1:32:23 PM4/26/17
to MIT App Inventor Forum
Segment: Start (2) + length (1) - 1 exceeds text length (0).
Note: You will not see another error reported for 5 seconds.

This happens when I enter a word on Screen 2.

Screen 2 just has "When Start Button Clicked, close screen with value result EnteredWord.Text"

Italo

unread,
Apr 26, 2017, 1:48:44 PM4/26/17
to mitappinv...@googlegroups.com
You are confused. Your HideWord procedure is not doing what is supossed to do. 
That procedure is evaluating if the letter typed is in the word. It should be named EvaluateLetter, for better understanding.

Like I said before, don't mix the procedures. First, you need a different procedure to MASK the word with _, so make a new procedure and call it MaskWord.
Rename the procedure HideWord for EvaluateIfLetterIsInWord.

Do these changes.
1  Rename the procedure HideWord for EvaluateIfLetterIsInWord.
2. Move *1 and *2 INSIDE the IF block, before the join
3. Delete that block after the IF block.
4  Create procedure MaskWord that only do that, it doesn't need to evaluate the letter or anything else. If I type COMPUTER, it should return C _ _ _ _ _ _ R, that's it. 
5  When the app returns from the other screen with the word to guess, call the MaskWord procedure. 
6  Every time the user types a letter to guess, call the EvaluateIfLetterIsInWord procedure


Ethan Schafer

unread,
Apr 27, 2017, 11:20:23 AM4/27/17
to MIT App Inventor Forum
I'm really sorry I keep wasting your time because I don't know how to do this, but I folllowed your steps and now I have another runtime error

Runtime Error
Segment: Start (2) + length (1) - 1 exceeds text length (0).
Note: You will not see another error reported for 5 seconds.


Taifun

unread,
Apr 27, 2017, 11:26:43 AM4/27/17
to MIT App Inventor Forum
Segment: Start (2) + length (1) - 1 exceeds text length (0).
before using the segment block use another if statement to check, if the text is long enough...

if length(text) > 2
then if segment ...
else show notifier "sorry, your text is not long enough"

you can find the length block in the text drawer
Taifun

Ethan Schafer

unread,
Apr 27, 2017, 11:36:07 AM4/27/17
to MIT App Inventor Forum

No luck. All of the words tested were more than 2 letters long, so it was a long shot.
Message has been deleted

Taifun

unread,
Apr 27, 2017, 11:47:05 AM4/27/17
to MIT App Inventor Forum
the length of your hiddenWord also must be long enough...
Taifun

Ethan Schafer

unread,
Apr 27, 2017, 12:13:22 PM4/27/17
to MIT App Inventor Forum

Runtime Error
Segment: Start (2) + length (6) - 1 exceeds text length (5).

Note: You will not see another error reported for 5 seconds.


Taifun

unread,
Apr 27, 2017, 2:11:46 PM4/27/17
to MIT App Inventor Forum
if length(text) > 2
then if segment ...
else show notifier "sorry, your text is not long enough"
sorry, this was the solution for the error message you posted earlier, I previously did not take a look at your blocks...
you are modifying the start position, so the length to check has to be a variable length...

this is the correct tip: before using the segment block make sure, the text is long enough...

probably it helps to find the bug, if you to try it step by step using an example word?
sorry, I do not have time to take a look more in detail... maybe @Italo can help...

Taifun

Italo

unread,
Apr 27, 2017, 2:35:31 PM4/27/17
to MIT App Inventor Forum
You have to check if the word is longer than 2 letters in the other screen, before going back to Screen1, It's doesn't make sense to do it in Screen1. 
If the word is shorter, then show a notification and the user will have to enter a new word.

Italo

unread,
Apr 27, 2017, 2:41:58 PM4/27/17
to MIT App Inventor Forum
Also, how are you capturing/attaching  the image of your blocks? It's really hard to read.
When you place the image in your post, please click on it and this little menu will show under it (see image below). Select ORIGINAL SIZE, please.





Italo

unread,
Apr 27, 2017, 2:49:06 PM4/27/17
to MIT App Inventor Forum


Abraham Getzler

unread,
Apr 27, 2017, 3:46:49 PM4/27/17
to MIT App Inventor Forum
You should read some working code to see how Hangman works.

See attached blocks images (no .aia file, you have to work here.)

ABG

mask.PNG
Capture3.PNG
Designer.PNG
globals.PNG
lpkRemaining_AfterPicking.PNG
remove.PNG
Screen1_Initialize.PNG
solicitMove.PNG
solicitNewWord.PNG
blocks.png
btnStartEnd_Click.PNG
Capture.PNG
Capture2.PNG
Reply all
Reply to author
Forward
0 new messages