Chameco
November 21st, 2010, 02:49 PM
Hello. I have recently started programing a small game in python using pygame, which I eventually plan to grow into a not-so-small game. I am competent with pygame (read: I can hobble along), but have recently had a problem. I am trying to organize the properties of various tiles using a two-dimensional nested list. I have a problem with subscripting. I am trying to use a while loop nested within another while loop to check to see if there are any "columns" left (the nested list), and if there are, executing the second loop to write values to all the objects in the column. I tried to use variables as list subscripts, but realized that it was just trying to use the second variable as a subscript to the first. This whole paragraph is probably incomprehensible, so here is my code.
def redrawScreenWithCharPosition(charPositionX, charPositionY):
row = [[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0]]
moreRowsLeft = 0
moreCollumnsLeft = 0
while moreCollumnsLeft <= 9:
while moreRowsLeft <= 9:
if row[moreCollumnsLeft[moreRowsLeft]] != 1:
row[moreCollumnsLeft[moreRowsLeft]] = 0
pixelCoordinateCollumn = moreCollumnsLeft * 50
pixelCoordinateRow = moreRowsLeft * 50
screen.blit(tile, (pixelCoordinateCollumn, pixelCoordinateRow))
pygame.display.flip()
moreCollumnsLeft = moreCollumnsLeft + 1
moreCollumnsLeft = moreCollumnsLeft + 1
moreRowsLeft = 1
def redrawScreenWithCharPosition(charPositionX, charPositionY):
row = [[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0]]
moreRowsLeft = 0
moreCollumnsLeft = 0
while moreCollumnsLeft <= 9:
while moreRowsLeft <= 9:
if row[moreCollumnsLeft[moreRowsLeft]] != 1:
row[moreCollumnsLeft[moreRowsLeft]] = 0
pixelCoordinateCollumn = moreCollumnsLeft * 50
pixelCoordinateRow = moreRowsLeft * 50
screen.blit(tile, (pixelCoordinateCollumn, pixelCoordinateRow))
pygame.display.flip()
moreCollumnsLeft = moreCollumnsLeft + 1
moreCollumnsLeft = moreCollumnsLeft + 1
moreRowsLeft = 1