Ask coding questions

← Back to all posts
What is the problem?
ichbindede (0)

I was writing a simple game when I try to run, it says:
/usr/bin/run-project
main.py:125: SyntaxWarning: "is" with a literal. Did you mean "=="?
if bullet_state is "ready":
main.py:181: SyntaxWarning: "is" with a literal. Did you mean "=="?
if bullet_state is "fire":
pygame 2.0.1 (SDL 2.0.14, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "main.py", line 120, in <module>
if event.key == pygame.K_a:
AttributeError: 'Event' object has no attribute 'key'
exit status 1

And here is the line 120:
if event.key == pygame.K_a:

Comments
hotnewtop
Coder100 (18876)

As you can see, you made a typo, it is event.type, not event.key!
You had it correct on lines 116 and 118, so fix it for the rest of the code.

ichbindede (0)

@Coder100 yeah but when I do it event.type I can't control the chaachter.

ichbindede (0)

@Coder100 I'll try pygame.key too. But I still can't understand why I can't control my character.

Coder100 (18876)

right
because event.type tells you only what type of event is being called i believe @ichbindede

ichbindede (0)

@Coder100 Ok, so what can I do to control my character.