Help using JavaScript for a hangman game

Ok, based on what you said, this is actually really easy. You don't need anything fancy. You don't even need an array.

I will make an example of a piece of what you need and then you just need to scale it to whatever puzzle you want.
Mods - sorry for the double post. Just needed to get the OP's attention.

@blanketorghost

Take a look at this sample video. Is this the functionality you were looking for? If so, this is quite easy to make and I can post screenshots of the necessary pieces. Then you just have to expand it to have all the letters of the alphabet and whatever puzzle answer you want.



I hope this is what you are looking for.
Mods - sorry for the double post. Just needed to get the OP's attention.

@blanketorghost

Take a look at this sample video. Is this the functionality you were looking for? If so, this is quite easy to make and I can post screenshots of the necessary pieces. Then you just have to expand it to have all the letters of the alphabet and whatever puzzle answer you want.



I hope this is what you are looking for.

Yeah, that's exactly it!
I have tried making the hangman myself but have found some bumps in the road while working it like:
1.the game freezing after the first answer input (when an image appears after requisite is met)
2.The other letter answers being labelled as wrong (when nested inside the initial letter's 'if' statement so the 'else' can be used for reducing the 'chances' variable)

I haven't coded wrong answers for the un-nested code, since I first wanna work out if I should put the decrease somewhere else or if I should instead just use a completely different method

I was also wondering how to show the hangman being built since the trigger condition in an average event page only allows the trigger to be 'greater than or equals' rather than 'lesser than or equals' which is what I would need so the hangman pieces can stack on one another.
SC and videos below:



EDIT: I also realized answers are case-sensitive, which now I wonder if maybe there's a way that the code can recognize the letter regardless of that

also that the "If chances = 0" code that causes a game over needs to be nestled inside the "If chances =/=0 (have also tried chances are greater to 0)" code to work, which feels... wrong in a way? since the code should run on its own once chances reach 0, and the other code should run when chances are still over 0
Here is a very simple way of doing this with a couple of caveats. This only works so simply because you have only 1 puzzle. So you know if a letter choice is correct or not and you know where the letter is supposed to go in the puzzle. This would be more complex if you had multiple puzzles.

There are two screenshots of the Event that sets up the puzzle. It is essentially just using Show Picture to place images were you want them on the screen through trial and error until it looks right. These are also examples of using the TextPicture plugin to show letters and the ButtonPicture plugin to make those letters clickable. Since I made this Event a parallel Event for the example, the last command line just turns on Self Switch A to change to page 2, which is empty and Action Button.

You would just have to add all the letters to this Event so the entire alphabet is showing where you want them to be.

And you would have to add as many spaces for the puzzle answer as appropriate. I used boxes because I had them available from my Sudoku puzzle.

Essentially, you could just follow this example and add or change whatever is needed.

Hangman Set Up 1.pngHangman Set Up 2.png

Then there is a screenshot for if a letter chosen is correct. It is very simple. You have a Variable tracking how many correct letters have been chosen. Because you already know the answer. I made a very simple example, but if the letter A appears twice in the puzzle, you have to increase the Variable by 2 instead of 1. The Common Event for that letter also has to show the letter in the puzzle in the appropriate spot. I didn't use an Erase Picture command because I was just reusing the Image number. That makes the letter disappear from the alphabet area and appear wherever you make it in the puzzle. If the letter A was used twice, you would just add the commands to have the letter A appear twice and use another Image number for the 2nd A.

Then there is a simple Conditional Branch to check if the Variable is equal to the total number of letters in the puzzle. If so, do whatever you want to end the puzzle. If not, the Common Event just ends and the game waits for the player to chose again.

Each Common Event for a correct letter looks just like this only you change the Image numbers, text letter, and locations as appropriate.

Hangman Letter Correct.png

Each Common Event for an incorrect letter is a bit different, but also the same except changing Image numbers, letters, and locations. You have another Variable tracking how many incorrect letters have been chosen. This only increases by 1 each time. You erase that Image to remove the letter from the alphabet area. Then you have a series of Conditional Branches checking the value of the Variable. If 1, show the first image in your hangman. If 2, show the second image (part) of the hangman, etc. Do that until you have a Conditional Branch for each piece of the hangman. You can actually use the same Image number for that, you would just need different images for the hangman as it progresses.

I didn't have those assets so I just used a simple X for this example. And you Show Picture wherever you want the hangman to appear.

In the last Conditional Branch, if the Variable equals the total number of guesses you allow, you also have your losing results of whatever you want in that conditional branch.

Hangman Letter Incorrect.png

So, with these 4 screenshots, you should be able to add the rest of the alphabet and make the necessary Common Events for all the letters.

Again, this only works this way because you have only 1 puzzle. One thing I didn't add was a sound effect when you click on the letters or get a letter wrong. That is very easy to add. I just didn't think about it.

Just pay attention to your Image numbers.

I think this explains the necessary concepts and screenshots and isn't really complex. Feel free to ask any questions.

I hope this helps and good luck!
Here is a very simple way of doing this with a couple of caveats. This only works so simply because you have only 1 puzzle. So you know if a letter choice is correct or not and you know where the letter is supposed to go in the puzzle. This would be more complex if you had multiple puzzles.

There are two screenshots of the Event that sets up the puzzle. It is essentially just using Show Picture to place images were you want them on the screen through trial and error until it looks right. These are also examples of using the TextPicture plugin to show letters and the ButtonPicture plugin to make those letters clickable. Since I made this Event a parallel Event for the example, the last command line just turns on Self Switch A to change to page 2, which is empty and Action Button.

You would just have to add all the letters to this Event so the entire alphabet is showing where you want them to be.

And you would have to add as many spaces for the puzzle answer as appropriate. I used boxes because I had them available from my Sudoku puzzle.

Essentially, you could just follow this example and add or change whatever is needed.

View attachment 313137View attachment 313138

Then there is a screenshot for if a letter chosen is correct. It is very simple. You have a Variable tracking how many correct letters have been chosen. Because you already know the answer. I made a very simple example, but if the letter A appears twice in the puzzle, you have to increase the Variable by 2 instead of 1. The Common Event for that letter also has to show the letter in the puzzle in the appropriate spot. I didn't use an Erase Picture command because I was just reusing the Image number. That makes the letter disappear from the alphabet area and appear wherever you make it in the puzzle. If the letter A was used twice, you would just add the commands to have the letter A appear twice and use another Image number for the 2nd A.

Then there is a simple Conditional Branch to check if the Variable is equal to the total number of letters in the puzzle. If so, do whatever you want to end the puzzle. If not, the Common Event just ends and the game waits for the player to chose again.

Each Common Event for a correct letter looks just like this only you change the Image numbers, text letter, and locations as appropriate.

View attachment 313135

Each Common Event for an incorrect letter is a bit different, but also the same except changing Image numbers, letters, and locations. You have another Variable tracking how many incorrect letters have been chosen. This only increases by 1 each time. You erase that Image to remove the letter from the alphabet area. Then you have a series of Conditional Branches checking the value of the Variable. If 1, show the first image in your hangman. If 2, show the second image (part) of the hangman, etc. Do that until you have a Conditional Branch for each piece of the hangman. You can actually use the same Image number for that, you would just need different images for the hangman as it progresses.

I didn't have those assets so I just used a simple X for this example. And you Show Picture wherever you want the hangman to appear.

In the last Conditional Branch, if the Variable equals the total number of guesses you allow, you also have your losing results of whatever you want in that conditional branch.

View attachment 313136

So, with these 4 screenshots, you should be able to add the rest of the alphabet and make the necessary Common Events for all the letters.

Again, this only works this way because you have only 1 puzzle. One thing I didn't add was a sound effect when you click on the letters or get a letter wrong. That is very easy to add. I just didn't think about it.

Just pay attention to your Image numbers.

I think this explains the necessary concepts and screenshots and isn't really complex. Feel free to ask any questions.

I hope this helps and good luck!
Thank you so much! I think I get it, but I'll let you know if I have any trouble with the eventing process later on,

Again, thank you so much for your patience!

Original thread: https://forums.rpgmakerweb.com/threads/help-using-javascript-for-a-hangman-game.170695/