Hello everyone! I am trying to make a snake in pygame but i came across an error that said:
TypeError: rect argument is invalid
Does anyone know how to fix this?
Hello everyone! I am trying to make a snake in pygame but i came across an error that said:
TypeError: rect argument is invalid
Does anyone know how to fix this?
The argument of the pygame.draw.rect
function, which is defined as a list in your code, must be a tuple. In addition, you placed this argument outside the brackets, which is incorrect, and the color of the rectangle is not specified in the tuple.
Corrected drawing code:
pygame.draw.rect(game_screen, (255, 255, 255), (x, y, 10, 10))
Welcome to the community @amellietjes900. I am not able to help you with this but we have a lot of others that are really good at coding. Just wanted to welcome you to the community! Hope you enjoy your time!
Wouldn’t pygaame.Rect(x, y, 10, 10)
also work?
Yes, that should also work.
Thank you all for the replies. Ive tried following the steps recommended to me, but it still didn’t work (
Are you still getting the same error?
I did get the same error, again.
Can you send your full code? Be sure to wrap it in a code block
```py
# your code here
```
pygame.draw.rect (game_screen,255,0,0), [food_x,food_y,10,10]
Replace this code with this one:
pygame.draw.rect(game screen, (255, 0, 0), (food_x, food_y, 10, 10))
You forgot to put an opening parenthesis before 255
.
You need to delete line 24.
Okay, I did the delete line 24 now. I am able to see the red dot now in the game but not the moving one.
Is the code now right u think? I hope I followed the steps right.
As the error says, you need to replace pygame.DOWN
with pygame.K_DOWN
.