Python Forum
[PyGame] Variables shared between game states, how to?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Variables shared between game states, how to?
#2
Location and money aren't global concepts, though. If there's two players, they could both be in different places and have different amounts of money. So I'd suggest a class to hold data and actions that are unique to players. Something like...
class Player:
    def __init__(self, start_location, start_money=0):
        self.location = start_location
        self.money = start_money
Then in the Control.__init__ you'd create your players, and either a) pass that list to the states when you call it's .startup() method so they know about the players, or b) pass the list to both the get_event() and the update() methods.
Reply


Messages In This Thread
RE: Variables shared between game states, how to? - by nilamo - Dec-09-2019, 04:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Best way to pass data to the few game states with the same superclass? Milosz 5 3,097 Oct-20-2021, 01:47 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020