Python: variables inside class methods

后端 未结 3 588
情深已故
情深已故 2021-01-23 04:13

I\'m learning python and am trying to write a wound system based on hot zones of a character. Here\'s what I\'ve written. Don\'t judge me too much.

class Charact         


        
3条回答
  •  独厮守ぢ
    2021-01-23 04:54

    Every local variable assigned within a function is thrown away as soon as the function ends. You need to prepend self. to those names so that they are saved as instance variables, such as self.l_arm, self.r_arm, and so on. The same goes for the wound pretty names, if you plan on using those objects later on.

提交回复
热议问题