1

I've tried to run the code as normal, however I was met with a error which looks something like this

Traceback (most recent call last):
  File "H:\Coursework assets\gametest1.py", line 85, in <module>
    wizard.move(wizard.x)
AttributeError: 'tuple' object has no attribute 'move'

Below is the class for the original player Player class for the main character. Where the error may have originated from

class player:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.standing = True
        self.left = False
        self.right = True
        self.vel = 15
    def move(self,x,y):
        if not(self.standing):
            if k[pygame.K_LEFT] and self.x  > 0 - 150:
                self.left = True
                self.right = False            
                self.x -= self.vel
            elif k[pygame.K_RIGHT] and self.x  < 500 - 150 :
                self.right = True
                self.left = False
                self.x += self.vel
        else:
            self.standing = True
   run = True

Main game loop

wizard = (25,420)
while run:#main game loop
    pygame.time.delay(15)
    wizard.move(wizard.x,wizard.y)
    win.blit(bg,(0,0))
    wizard.jump(wizard.y)
    wizard.draw(win)) 
    pygame.display.update()
pygame.quit()
1
  • 1
    I am deeply puzzled as to what your variable 'wizard' is supposed to be! You have assigned a tuple to it but you appear to be trying to treat it as an instance of your player class! Do you mean to set up a player called wizard? In which case you need to replace the first line of your game loop with 'wizard = player(45,420)' Commented Nov 17, 2019 at 14:21

2 Answers 2

2

In the game loop, the wizard you create is just a tuple. Create it as wizard = player(25, 420)

Also, it is heavily recommended to make class names capital (Player). See PEP 8 for more coding style recommendations which are generally accepted by Python community.

Moreover, you don't have to put parentheses around the negated statement, just as if not self.standing. And you probably actually don't want the not there, you want to move the wizard if he is standing, and raise him when he isn't...

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your wizard is meant to be "player" class, the deceleration of the variable wizard is not correct.

The code has:

wizard = (25,420)

Which just makes the wizard a pair of numbers. ( Known as a "tuple ).

I think this should be an instance of player, with the x and y parameters of 25, 240 ~

wizard = player( 25, 420 )

I assume you left the functions player.jump() and player.draw() out of the code, but if they are not written yet, your main loop will break with much the same error you already reported, except for .jump() first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.