title: global name self is not defined python
body: <p>Hey guys I don't know what is going wrong with my python/pygame game it's keeps giving me this error when try to run it with the IDLE</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:/code/gmaes/game/adad.py&quot;, line 102, in &lt;module&gt;
      Game().main(screen)
    File &quot;C:/code/gmaes/game/adad.py&quot;, line 95, in main
      self.tilemap.update(dt/1000.,self)
    File &quot;C:/code/gmaes/game\tmx.py&quot;, line 689, in update
      layer.update(dt, *args)
    File &quot;C:\Python27\lib\site-packages\pygame\sprite.py&quot;, line 399, in update
      for s in self.sprites(): s.update(*args)
    File &quot;C:/code/gmaes/game/adad.py&quot;, line 36, in update
      if self.resting and key[pygame.K_SPCAE]:
  NameError: global name 'self' is not defined
  </code></pre>
  <p>I don't know why im getting this error and i have never gotten this problem before, I was hoping you guys and girls could help. Here is my full code, take a look and leave your thoughts</p>
  <h1>Main Run File For Python game !python/pygame</h1>
  <pre><code>import pygame
  import tmx
  
  class Player(pygame.sprite.Sprite):
      def __init__(self,location,frames,*groups):
          super(Player,self).__init__(*groups)
          self.frame = 0
          self.frames = frames
          self.image = self.frames[self.frame]
          self.rect = pygame.rect.Rect(location,self.image.get_size())
          self.resting = False
          self.dy = 0
          self.is_dead = False
          self.direction = 1
      def update(slef,dt,game):
          last = slef.rect.copy
          key = pygame.key.get_pressed()
          if key[pygame.K_LEFT]:
                  self.rect -= 300 * dt
                  self.direction = -1
                  self.frame = self.frame
                  self.frame += 1
                  self.image = self.frames[frame]
                  if self.frame &gt; 2:
                          self.frame = 0
          if key[pygame.K_RIGHT]:
                  self.rect -= 300 * dt
                  self.direction = 1
                  self.frame = self.frame
                  slef.frame += 1
                  self.image = self.frames[frame]
          if slef.frame &gt; 2:
                  self.frame = 0
  
          if self.resting and key[pygame.K_SPACE]:
                  self.dy = -500
          self.dy = min(400,self.dy + 40)
          self.rect.y += self.dy  * dt
  
          new = self.rect
          self.resting = False
  
          for cell in game.tilemap.layers['triggers'].collide(new,'blockers'):
              blockers = cell['blockers']
              if 'l' in blockers and last.right &lt;= cell.left and new.right &gt; cell.left:
                  new.right = cell.left
              if 'r' in blockers and last.left &gt;= cell.right and new.left &lt; cell.right:
                  new.left = cell.right
              if 't' in blockers and last.bottom &lt;= cell.top and new.bottom &gt; cell.top:
                  self.resting = True
                  new.bottom = cell.top
                  self.dy = 0
              if 'b' in blockers and last.top &gt;= cell.bottom and new.top &lt; cell.bottom:
                  new.top = cell.bottom
                  self.dy = 0
              game.tilemap.set_focus(new.x,new.y)
  
  
  class sprite_system(object):
      def slice_sheet(self,sprite_sheet,sprite_start_x,sprite_start_y,sprite_size_x,sprite_size_y,sheet_frames):
          frame = []
          sheet_start = 1
          frame_pos = 0
          sprite_start_x_base = sprite_size_x
          while sheet_start &lt;= sheet_frames:
              sheet = sprite_sheet
              sheet.set_clip(pygame.Rect(sprite_start_x,sprite_start_y,sprite_size_x,sprite_size_y))
              sprite_clip = sheet.subsurface(sheet.get_clip())
              frame.append(sprite_clip)
              sprite_start_x += sprite_start_x_base
              sheet_start += 1
          return frame
  
  
  class Game(object):
      def main(self,screen):
          sprite = pygame.image.load('test.png')
          frames = sprite_system().slice_sheet(sprite,0,0,64,64,4)
          clock = pygame.time.Clock()
          self.tilemap = tmx.load('lvl1.tmx',screen.get_size())
          self.sprites = tmx.SpriteLayer()
          start_cell = self.tilemap.layers['triggers'].find('player')[0]
          self.player = Player((start_cell.px,start_cell.py),frames,self.sprites)
          self.tilemap.layers.append(self.sprites)
  
          while 1:
              dt = clock.tick(30)
  
              for event in pygame.event.get():
                  if event.type == pygame.QUIT:
                          return
                  if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                          return
              self.tilemap.update(dt/1000.,self)
              self.tilemap.draw(screen)
              pygame.display.flip()
  
  if __name__ == '__main__':
      pygame.init()
      screen = pygame.display.set_mode((854,480))
      Game().main(screen)
  </code></pre>
  <p>oh and here is the snipet of code that is failing</p>
  <pre><code>if self.resting and key[pygame.K_SPACE]:
          self.dy = -500
          self.dy = min(400,self.dy + 40)
          self.rect.y += self.dy  * dt
  
          new = self.rect
          self.resting = False
  </code></pre>