I'm working on a Python program using Pygame, and I'm trying to refine the logic for displaying answers. Currently, whenever I press a matching key, it immediately shows the response. What I want instead is for the key press to register first, and then only show the response when I press it a second time. I have the following code structure, but I'm running into issues with it. Any advice on how I can achieve this?
2 Answers
The problem seems to be that you’re re-initializing the `guessed_letter` list each time `displayAnswers()` is called. You should make `guessed_letter` a global variable or pass it as a parameter so that it retains its values between function calls. This way, you can keep track of letters that have already been pressed. Have a look at your structure and see if maintaining its state helps!
I attempted some changes based on this advice, but I'm still hitting a wall. Maybe there’s another issue?
From what I gather, you could use a simple list to track inputs. You can display the response only if the key pressed is the last one in the list. For example, if your code looks like this: `list=[]` and when the key input `x` is pressed, you check if it's the last element in that list. If it is, then show the response. If not, indicate that the key was pressed and wait for the next click to show the response. Check this logic and see if it fits your needs!
That makes sense! I'm keeping track of which correct letters have been clicked using a list. If the player clicks again, I need to show the response based on that.

I understand your confusion! Originally, I placed `guessed_letter` outside the function too, thinking it would work better. But it’s tricky. Have you tried adjusting its scope and seeing if that remedies the issue?