0

I have a little Problem with this code-snippet:

GrasTexture = pygame.image.load('Textures/Grounds/Gras.png')
StoneTexture = pygame.image.load('Textures/Grounds/Stone.png')
PathTexture = pygame.image.load('Textures/Grounds/Path.png')
SandTexture = pygame.image.load('Textures/Grounds/Sand.png')
SnowTexture = pygame.image.load('Textures/Grounds/Snow.png')
WaterTexture = pygame.image.load('Textures/Grounds/Water.png')
for i in range(936000):
        if(mapList[i][0] == 0):
            screen.blit(GrasTexture, (posX,posY))
        elif(mapList[i][0] == 1):
            screen.blit(StoneTexture, (posX,posY))
        elif(mapList[i][0] == 2):
            screen.blit(PathTexture, (posX,posY))
        elif(mapList[i][0] == 3):
            screen.blit(SandTexture, (posX,posY))
        elif(mapList[i][0] == 4):
            screen.blit(SnowTexture, (posX,posY))
        elif(mapList[i][0] == 5):
            screen.blit(WaterTexture, (posX,posY))
        if(posX != 144000):
            posX += 80
        else:
            posY += 80
            posX = 0

The map was created like this:

list01 =  [[0,0,0] for i in range(936000)]
f = open("map.txt", "w")
f.write(str(list01))
f.close()
f = open("map.txt", "r")
mapList = f.read()
mapList = ast.literal_eval(mapList)
f.close()

Here is the problem: When I change something in the mapList like mapList[0][0] = 4, the Texture doesn't change. But when I cut the for-loop out and replace the i by a 0. The Texture is right. So what is my Problem? Please help me!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 2
    What do you mean by 'change something in the mapList like mapList[0][0] == 4'? In case you are thinking mapList[0][0] == 4 would make an assignment; it is an equality check and will return just True or False. Please update your code with the snippet that is not working. – user3885927 Oct 01 '14 at 20:41
  • I edited it. So whats now? –  Oct 01 '14 at 20:49
  • 2
    you don't show where you assign 4 to mapList. It's likely that's where the error is. – tdelaney Oct 01 '14 at 21:01
  • 1
    what is the output if you add these lines after f.close('|' is just a delimiter I used for end of line.)? print "changing map" | print mapList[0][0] | mapList[0][0]=5 | print mapList[0][0] – user3885927 Oct 01 '14 at 21:02
  • @tdelaney no it isn't. Tested it. –  Oct 01 '14 at 21:09
  • Output is: changing map | 0 | 5, thats the big problem. It seems that everything works fine but it doesn't show it on the screen. –  Oct 01 '14 at 21:11
  • 1
    This is a case where you might want to use xrange (in certain python versions). – David Ehrmann Oct 01 '14 at 21:17
  • @David I use python3. –  Oct 01 '14 at 21:21
  • 1
    "changing map | 0 | 5" shows that mapList[0][0] was a zero, not a 4. How about a print right before the for loop: `print(mapList[0][0], posX, posY)`. – tdelaney Oct 01 '14 at 21:25
  • I don't get the problem!!! When i save the map.txt after changing the mapList, everything is right. When I show it with a for-loop, the textures are wrong. When I do screen.blit(mapList[0][0],(0,0)) it works fine. Thats horrible... –  Oct 01 '14 at 21:28
  • @tdelaney I deleted the mapList[0][0] = 4 before I made this test. So it's right. –  Oct 01 '14 at 21:33
  • @tdelaney mapList[0][0], posX and posY are all 0 –  Oct 01 '14 at 21:35
  • that means that, at the point the loop is run, mapList[0][0] wasn't set to 4. The problem, as I understand it, is that if you do something like `mapList[0][0] = 4`, the texture stays at zero, which is GrasTexture. But the thing is, you haven't changed mapList[0][0] to 4. For debug, you could delete the entire for loop and replace it with `assert mapList[0]0[] ==4` and you'd be seeing the assert. Its not the for loop itself. – tdelaney Oct 01 '14 at 21:42
  • So what do you think the problem is? –  Oct 01 '14 at 21:46
  • It also doesn't works with a While-loops. Tested it right now. –  Oct 02 '14 at 13:42
  • Have you tried using `sys.setrecursionlimit`? –  Oct 05 '14 at 01:31
  • this probably doesnt help but I would use pickle to save arrays. – Julius Naeumann Oct 05 '14 at 18:55

0 Answers0