Python Forum
[PyGame] Confusion regarding 'self' while creating instance
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Confusion regarding 'self' while creating instance
#1
Hi people

I am a total noob to programming and trying to learn python from "Python Crash Course".

I am currently working on making the "Alien Invasion" game.

The book tells me to create instances of two classes (from different files) as follows:

self.settings = Settings()
self.ship = Ship(self)
Why do I have to use 'self' for one and not for the other?

Thanks
Reply
#2
self refer to class object.
Settings is probably data that is read. Doesn't effect the current object.
Ship needs to read data from current object. It need a way to point to it. So you pass self.

Source code will tell you a lot more.
Without seeing Ship class. Can't tell you what it actually doing.
99 percent of computer problems exists between chair and keyboard.
Reply
#3
Thanks. I get it
Reply


Forum Jump:

User Panel Messages

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