Godot Version
4.3
Ok, so I’m learning Godot and wanted to make Minesweeper to teach myself tilemaps, but I’m stumbling at the first hurdle because my program isn’t iterating over the last elements in my arrays.
So I have an array of arrays called mine_map that I iterate over in a prior function to place mines, then it calls this function to iterate over the tiles and increase the value of each gridspace based on how many mines are near it. I’m sure there’s a much better way to do what I’m trying to, but this is what I’ve come up with so far:
func generate_tiles():
for x in range(9):
for y in range(9):
#10 is a mine, ignore the space if there's a 10 here.
if mine_map[x][y] != 10:
#check 3 tiles above current tile
if mine_map[x-1][y-1] == 10:
mine_map[x][y] += 1
if mine_map[x][y-1] == 10:
mine_map[x][y] += 1
if mine_map[x+1][y-1] == 10:
mine_map[x][y] += 1
#check 2 tiles next to current
if mine_map[x-1][y] == 10:
mine_map[x][y] += 1
if mine_map[x+1][y] == 10:
mine_map[x][y] += 1
#check 3 tiles below current
if mine_map[x-1][y+1] == 10:
mine_map[x][y] += 1
if mine_map[x][y+1] == 10:
mine_map[x][y] += 1
if mine_map[x+1][y+1] == 10:
mine_map[x][y] += 1
I have a bunch of prints to test out the system, but the problem is, the function seems to be ignoring the last element in each ‘x’ array, as well as the last ‘x’ array in it’s entirety, so I get output like this:
[1, 10, 1, 1, 10, 2, 1, 2, 10, 0]
[1, 1, 1, 1, 2, 10, 1, 2, 10, 0]
[0, 0, 0, 0, 1, 1, 1, 1, 1, 0]
[1, 1, 1, 0, 0, 0, 1, 1, 1, 0]
[1, 10, 2, 1, 1, 0, 1, 10, 1, 0]
[1, 1, 2, 10, 1, 0, 1, 1, 1, 0]
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0]
[1, 1, 0, 0, 0, 1, 10, 1, 0, 0]
[10, 1, 0, 0, 0, 1, 1, 1, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Why won’t my for loop iterate over the last elements?