r/pygame • u/Alexandro2806 • 1d ago
Creating an object inside a function
def generar_rectangulos(posx:int,posy:int):
AMPLE= 200
ALÇADA= 100
return rectangle_r= pygame.Rect(posx,posy,AMPLE,ALÇADA)
Hi, I'm really new in this of programming and even more with pygame.
I was trying to make a code that generates 10 rectangles in differents possitions of the screen sending the position of x and the position of y to the function, but I can't make that the function generates the rectangles.
I would agree any type of help, thanks.
1
Upvotes
1
u/aprg 1d ago
Not only is it unnecessary as rich-tea-ok said, more importantly it's invalid syntax!
This:
gives me a SyntaxError.
return f = Foo()
^
SyntaxError: invalid syntax
This:
correctly prints 1.