getting an int from a list (pygame)
<p>i am trying to make a 'snake'-like game in python.
My problem right now is that I can't use the defined values from my 'coinlist' in my for-loop. This is the error that i receive if i execute it: TypeError: 'int' object is not subscriptable. Thanks for your help. </p>

<pre><code>import pygame
import random

pygame.init()

rot = (255,0,0)
grÃ¼n = (0,255,0)
blau = (0,0,255)
gelb = (255,255,0)
schwarz = (0,0,0)
weiÃ = (255,255,255)

uhr = pygame.time.Clock()

display = pygame.display.set_mode((800, 600))
pygame.display.set_mode((800, 600))
pygame.display.set_caption('Snake')
display.fill(weiÃ)


def arialmsg(msg, color, x, y, s):
  header = pygame.font.SysFont("Arial", s)
  text = header.render(msg, True, color)
  display.blit(text, [x, y])

def mainloop():
    gameExit = False
    start = False
    movex = 400
    movey = 300
    changex = 0
    changey = -2
    rx = random.randrange(10, 790)
    ry = random.randrange(10, 590)
    snakelist = []
    snakelenght = 20

    #coinlist defined here:
    coinlist = []

    while start == False:
        display.fill(schwarz)
        arialmsg('Snake', grÃ¼n, 350, 200, 25)

        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    start = True

        pygame.display.flip()

    #gameloop:

    while gameExit == False:

      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
          elif event.type == pygame.KEYDOWN:
              if event.key == pygame.K_DOWN:
                  changey = 2
                  changex = 0
              elif event.key == pygame.K_UP:
                  changey = -2
                  changex = 0
              elif event.key == pygame.K_RIGHT:
                  changex = 2
                  changey = 0
              elif event.key == pygame.K_LEFT:
                  changex = -2
                  changey = 0

      movex += changex
      movey += changey
      snakehead = []
      snakehead.append(movex)
      snakehead.append(movey)
      snakelist.append(snakehead)

      display.fill(schwarz)

      if len(coinlist) &lt; 1:
          rx = random.randrange(10, 790)
          ry = random.randrange(10, 590)
          coinlist.append(rx)
          coinlist.append(ry)

      for XY in snakelist:
        pygame.draw.circle(display, grÃ¼n, (XY[0], XY[1]), 10, 10)



for-loop for the coinlist:

      for coin in coinlist:
        pygame.draw.rect(display, grÃ¼n, (coin[0], coin[1], 10, 10))

      pygame.display.flip()

      if snakelenght &lt; len(snakelist):
          del snakelist[:1]

      if movex &gt;= rx - 19 and movex &lt;= rx + 19 and movey &gt;= ry - 19 and movey &lt;= ry + 19:
          del coinlist[:1]
          snakelenght += 10

      uhr.tick(15)
mainloop()

pygame.quit()
quit()
</code></pre>

<p>You're appending ints to coinlist (rx and ry are random ints from 10 to 790/590) and later on you're trying to access elements within coinlist as if they are arrays.</p>

<p>Consider doing something like replacing</p>

<pre><code>coinlist.append(rx)
coinlist.append(ry)
</code></pre>

<p>with</p>

<pre><code>coinlist.append([rx,ry])
</code></pre>

python for-loop pygame