title: Getting error "IndexError: list index out of range" when I try to use an activation function
body: <p>So I'm trying to write a game that uses NEAT to evolve the players in typical NEAT fashion, but the activation function gives me this error:</p>
  
  <pre><code>Traceback (most recent call last):
  ...
  File "C:/Users/me/py/neat.py", line 101, in main
  output = nets[homies.index(ind)].activate((ind.x, abs(obs[0].x - ind.x)))
  IndexError: list index out of range
  </code></pre>
  
  <p>I'm not entirely sure what to do here. I just kind of followed along with a Tech with Tim NEAT tutorial and I got this error, so any help would be greatly appreciated! Thanks in advance</p>
  
  <p>Here's the full code if you need it:</p>
  
  <pre><code>import pygame
  from pygame.locals import *
  import random
  import os
  import neat
  
  W = 300
  H = 300
  win = pygame.display.set_mode((W, H))
  pygame.display.set_caption("bruv moment")
  
  
  coords = [0, 60, 120, 180, 240]
  
  
  class Player(object):
      def __init__(self, x):
          self.x = x
          self.y = 600 - 60
          self.width = 60
          self.height = 60
          self.pos = 0
          self.left = False
          self.right = False
  
      def move(self):
          if self.left:
              self.pos -= 1
          if self.right:
              self.pos += 1
          if self.pos &lt; 0:
              self.pos = 4
          if self.pos &gt; 4:
              self.pos = 0
          self.x = coords[self.pos]
  
  
  class Block(object):
      def __init__(self, pos, vel):
          self.pos = pos
          self.x = coords[self.pos]
          self.y = -60
          self.width = 60
          self.height = 60
          self.vel = vel
  
      def move(self):
          self.y += self.vel
  
  
  def redraw_window():
      pygame.draw.rect(win, (0, 0, 0), (0, 0, W, H))
      for ob in obs:
          pygame.draw.rect(win, (0, 255, 0), (ob.x, ob.y, ob.width, ob.height))
      for ind in homies:
          pygame.draw.rect(win, (255, 0, 0), (ind.x, ind.y, ind.width, ind.height))
      pygame.display.update()
  
  
  obs = []
  homies = []
  player_collision = False
  
  ge = []
  nets = []
  
  
  def collide():
      for ob in obs:
          for x, ind in enumerate(homies):
              if ind.y &lt; ob.y + ob.height and ind.y + ind.height &gt; ob.y:
                  if ind.x + ind.width &gt; ob.x and ind.x &lt; ob.x + ob.width:
                      ge[x].fitness -= 1
                      homies.pop(x)
                      nets.pop(x)
                      ge.pop(x)
  
  
  def main(genomes, config):
      speed = 30
  
      pygame.time.set_timer(USEREVENT + 1, 550)
      pygame.time.set_timer(USEREVENT + 2, 1000)
  
      for _, g in genomes:
          net = neat.nn.FeedForwardNetwork.create(g, config)
          nets.append(net)
          homies.append(Player(0))
          g.fitness = 0
          ge.append(g)
  
      clock = pygame.time.Clock()
      ran = True
      while ran and len(homies) &gt; 0:
          clock.tick(27)
          collide()
          for x, ind in enumerate(homies):
              ind.move()
              ge[x].fitness += 0.1
  
              output = nets[homies.index(ind)].activate((ind.x, abs(obs[0].x - ind.x))) &lt;== ERROR TRACEBACK
  
              if output[0] &gt; 2:
                  ind.left = True
              else:
                  ind.left = False
              if output[1] &gt; 2:
                  ind.right = True
              else:
                  ind.right = False
          for ob in obs:
              ob.move()
              if ob.x &gt; H:
                  obs.pop(obs.index(ob))
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  ran = False
                  pygame.quit()
              if event.type == USEREVENT+1:
                  if speed &lt;= 200:
                      speed += 3
              if event.type == USEREVENT+2:
                  for g in ge:
                      g.fitness += 0.5
          if len(obs) == 0:
              obs.append(Block(round(random.randint(0, 4)), speed))
          redraw_window()
  
  
  def run(config_path):
      config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet,
                                  neat.DefaultStagnation, config_path)
  
      p = neat.Population(config)
  
      p.add_reporter(neat.StdOutReporter(True))
      stats = neat.StatisticsReporter()
      p.add_reporter(stats)
  
      winner = p.run(main, 50)
  
  
  if __name__ == "__main__":
      local_dir = os.path.dirname(__file__)
      config_path = os.path.join(local_dir, "avoidpedofiles.txt")
      run(config_path)
  </code></pre>