title: Error while calling class instances
body: <p>this program I am making in Python 2.7 with Pygame. It's my first attempt to create a game using classes. I am trying to initialize a class with stats for the hero, such as hp, speed, etc named 'archer'. When I try to run the code, it gives me this error:</p>
  
  <p><code>Traceback (most recent call last):
    File "C:/Python27/rpg.py", line 85, in &lt;module&gt;
      archer.walk()
  NameError: name 'archer' is not defined</code></p>
  
  <p>Here is my code.</p>
  
  <pre><code>from pygame import *
  from random import *
  from time import *
  import pygame
  init()
  ###############VARIABLES
  xmove = 0
  ymove = 0
  white = ( 255,255,255 )
  
  ###############INITIALIZING
  def preStuff():
      heroSelect()#choose a hero
      initiateScreen()#set screen size
  def initiateScreen():
      screen = display.set_mode ((500,500))
  def heroSelect():
      print """ Welcome to Boss Fights!
  Select a hero:
  Archer: Use a bow for long range attacks! Attacks do little damage, but can hit from far away. Has average health.
  
  Warrior: Smite enemies with his powerful sword! Attacks a very powerful, but have very short range and are quite slow. Has high health.
  
  Assasin: Hit your enemy without them even seeing you! Assasin moves very quickly, and attacks quickly Has low health.
  
  Alien: Blast your enemy with fire! Use a staff to shoot strong fireballs at enemies, with moderate damage and range. Has average health.
  
  
  """
      heroC = raw_input('Which class would you like?')
      if heroC == 'Archer' or 'archer' or 'ar':
          archer=Hero(50,250,image.load('archer.png'),100,.3,.1)#initialize Hero as: archer
      elif heroC == 'Warrior' or 'warrior' or 'w':
          warrior=Hero(50,250,image.load('warrior.png'),200,.4,.05)
      elif heroC == 'Assasin' or 'assasin' or 'as':
          assasin=Hero(50,250,image.load('asassin.png'),125,.1,.2)
      elif heroC == 'Alien' or 'alien' or 'al':
          alien=Hero(50,250,image.load('alien.png'),150,.3,.1)
  
  
  
  class Hero:    
      def __init__(self,x,y, blitImg,hp,attackspeed,speed):
          self.x=x
          self.y=y
          self.blitImg=blitImg
          self.hp = hp
          self.attackspeed = attackspeed
          self.speed=speed
  
  def walk(self):
  
      for event in pygame.event.get():
          if event.type==QUIT:
              pygame.quit()
              sys.exit()            
          if event.type == KEYDOWN:
              if event.key == K_s:
                  ymove = self.speed
              elif event.key == K_w:
                  ymove = -self.speed
              elif event.key == K_a:
                  xmove = -self.speed
              elif event.key == K_d:
                  xmove = self.speed
          elif event.type == KEYUP:
              if event.key == K_a or K_s or K_d or K_w:
                  xmove = 0
                  ymove = 0
      self.y += ymove
      self.x += xmove
      screen.fill( white )
      screen.blit(self.blitImg,(self.x,self.y))
      display.update()
  
  
  
  
  
  
  if __name__ == "__main__":
      preStuff()
      while True:
          archer.walk()
  </code></pre>
  
  <p>I am just trying to make the character walk for now.(and just the archer class)
  I have tried running </p>
  
  <pre><code>archer=Hero(50,250,image.load('archer.png'),100,.3,.1)
  </code></pre>
  
  <p>in the shell, and it works fine. I can call archer.y and the rest of the variables, and they print perfectly. Please someone help me figure out why this isnt working!. (P.S. I am a beginner programmer, so please forgive if it is some simple, easy fix that i'm too dumb to realize)
  Thanks!</p>