Oct-16-2022, 04:28 AM
world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns).
For your example:
"for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]:
For your example:
world_data = [ [ 1 ,1 ,1, 1, 1], [ 1 ,0, 0, 0, 1], [ 1 ,0, 0, 0, 1], [ 1 ,0, 0, 0, 1], [ 1 ,1 ,1, 1, 1], ]The first row is:
[ 1 ,1 ,1, 1, 1]and the first column is
[ 1, 1, 1, 1, 1 ],The way world_data is organized, it is very easy to loop through the rows, because each row is a list.
row[0] = [ 1 ,1 ,1, 1, 1] row[1] = [ 1 ,0, 0, 0, 1] row[2] = [ 1 ,0, 0, 0, 1] row[3] = [ 1 ,0, 0, 0, 1] row[4] = [ 1 ,1 ,1, 1, 1],The "for row in data:" loop will run 5 times, once for each row shown above. The first time through the loop it uses row[0], the second time through the loop it uses row[1]. This continues until the last loop uses row[4].
"for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]:
tile[0] = 1 tile[1] = 0 tile[2] = 0 tile[3] = 0 tile[4] = 1