0

I am having problems accessing a variable from one class to another.

class Player(pygame.sprite.Sprite):
    
    def rotateShip(self, rotAmt):
        
        radians = self.rotation * math.pi / 180

I am trying to use the variable radians from class Player to another class. radians only exists in 'rotateShip'.

Thanks for your help in advance.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Gribouillis
1

Since radians is only self.rotations converted to radians, it would be easier to make it a property

class Player(pygame.sprite.Sprite):
    
    def rotateShip(self, rotAmt):
        # here use self.radians

    @property
    def radians(self):
        return self.rotation * math.pi / 180

In other classes, use player.radians . In this case, you may consider renaming player.rotation to player.degrees.

Edited by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.