Help with coding a button

Hello, I am curious to know if anyone would be able to help me with something I am trying to achieve. So i am creating a game (a very simple one) where you have to guess the letters of my word and everytime you guess right, The correct letter you guessed, will appear on the canvas and the “letters to guess” number will decrease until you guess all right letters. The same goes for the “guesses left” number (everytime you guess a wrong letter the number decreases until you reach zero) however I am having much difficulty achieving this. I am very new to programming and i just cant figure out how to continuously decrease the numbers in value while at the same time making a letter appear or not (if the wrong letter is guessed) in the process. Please any help or tips would be appreciated and thank you in advance. This is what i have so far:

1 2 3

This sounds like the game Hangman.

Here’s a sample doc …

1 Like

Thanks for the info it was really helpful. I was able to almost achieve what I wanted with this procedure however the only thing im having an issue with now is that when the amounts of guesses run out i get a false returned not a zero. Then i changed the code around and the counter did not stop at zero it kept going if you kept on guessing letters. It kept going to -1, -2, etc. Im trying to make it stop at zero any helpful tip would be appreciated. The hangman info helped but I didnt wanted mine to be different, but here is my procedure so far any ideas on what is causing my issue. Thank you in advance. This is what I have so far:
i feel like ive been working on this for so long my brain is fried and i just cant comprehend the issue :confused:

If you are lost in a jungle of logic, you need to put up street signs.

Pay careful attention to your procedures to give them good functional descriptive names
for what value they are returning or what job they must do.

Likewise for variable names. Make sure you have good variable names, and do not fear creating intermediate value variables for stepping stones along the way to the end result.

i feel like the names are understandable enough, but is there something you see that im just not seeing or something else i can change?

You have not provided enough information to debug your program.

Because you did not name your procedure, we are unable to determine if it meets its objective.
You also did not show the context where it is called from, further denying us information.

You have a global variable named guess2.
Does that mean there is another variable named guess1, and another named guess3?
If the player is guessing letters in this game, why are you treating guess2 like a number?

Names are half the work in programming, and are the foundation for logic.
Your foundations are slipping into the mud.

1 Like

Oh, i see…your right…i guess I never thought of that. I understand it, but you made me realize that its also good practice to have others understand what these do as well and thank you for the advice I will definitely keep that in mind from now on. I’ll change the name ‘guess2’ to ‘correctGuessesleft’. Basically I have created a global variable correctGuessesLeft = 4 (because my word is 4 letters and this variable is what you do not see in the snippet i provided) and every time the user guesses a correct letter this procedure decrements correctGuessesleft by 1 until it reaches 0 and once it reaches 0 i dont want it to keep decrementing the value to -1, -2, etc. and I want the 0 to be displayed in the label i named lblLeftovernum (right now it returns ‘false’ once it reaches 0 and this is what im trying to correct)

It sounds like your procedure should be named handleWrongGuess,
and the decreasing the count of remaining guesses should be moved down
to the branch of the if/then that has room to decrease it further.
The if/then should be checking if remaining guesses > 0.
The count should never be allowed to go below 0, so that’s why you test before decrementing.