How can I fix my Pygame input logic to show responses only after clicking again?

0
1
Asked By CodeNinja88 On

I'm working on a Pygame project where I want to change the way user inputs are handled. At the moment, whenever I press a matching key, it automatically shows the response. Instead, I want the key to only show when pressed, and then display the response when clicked a second time. I'm using a list to keep track of the guessed letters, but I'm struggling with how to manage that across multiple function calls. Any suggestions on how to achieve this?

2 Answers

Answered By DevMaster99 On

It looks like you're resetting your `guessed_letter` array every time `displayAnswers()` is called. Try making it a global variable or pass it in as a parameter so it keeps its values between calls. That should help with your logic issue!

CodeNinja88 -

I originally had it outside the function, but I got confused and moved it inside. I'll change that back and see if it works!

DevMaster99 -

Let me know if that fixes it. It's important to keep track of state in a loop like this!

Answered By TechWhiz42 On

I think you could use a simple list to track selected keys. If the input matches the last key pressed, show the response; otherwise, update and just notify that it’s selected. Here's a basic structure to illustrate:

```python
list=[]
while True:
x=input_key
if x!=list[-1]:
print(x, 'is selected, click again to display response')
else:
display_response
break
```

CodeNinja88 -

I'm already using a list for correct characters clicked. I need it to show the response only when a key is clicked again.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.