user9905822
user9905822

Reputation: 13

TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method

Full code here: https://pastebin.com/Ne3dCpzp

Dice0 = pygame.image.load("dice_0.png").convert
Dice1 = pygame.image.load("dice_1.png").convert
Dice2 = pygame.image.load("dice_2.png").convert
Dice3 = pygame.image.load("dice_3.png").convert
Dice4 = pygame.image.load("dice_4.png").convert

dice0img = Dice0
dice1img = Dice1
dice2img = Dice2
dice3img = Dice3
dice4img = Dice4

...

    if dice == 0 :
        screen.blit(dice0img, (80, 320))
    if dice == 1 :
        screen.blit(dice1img, (80, 320))
    if dice == 2 :
        screen.blit(dice2img, (80, 320))
    if dice == 3 :
        screen.blit(dice3img, (80, 320))
    if dice == 4 :
        screen.blit(dice4img, (80, 320))

Im currently getting an error:

Traceback (most recent call last):
  File "C:\Users\Ed\Documents\thonk\game.py", line 90, in <module>
    screen.blit(dice4img, (80, 320))
TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method

Why is this happening?

Upvotes: 1

Views: 695

Answers (1)

sloth
sloth

Reputation: 101072

As the error message tells you, you have to pass an Surface to the blit function.

If you look at these lines of your code:

Dice4 = pygame.image.load("dice_4.png").convert
...
dice4img = Dice4

you can see that Dice4 / dice4img are references to the convert function. Again, that's also something the error message tells you (not builtin_function_or_method).

You have to actually call the convert function so it returns a Surface and assign it to the Dice4 variable.

TL;DR:

The lines that look like

Dice4 = pygame.image.load("dice_4.png").convert

should look like this

Dice4 = pygame.image.load("dice_4.png").convert()

Upvotes: 1

Related Questions