Feedback: Danger Valley

So what exactly is your request?

Hey GundericusTheMighty!
Taking the information from this post, if i understood correctly:

for i in array:

results in doing something with every element in the array, but not going through the index.
so if it would be [0,1,0,1,0]
youā€™d get at the first iteration of the for loop the 0, the second would be 1, but the third would be 0 again.

for i in range(len(array)):

Would give you the index to the variable i, instead of the element.
so the result would be: 0, 1, 2, 3, 4
and then you would be able to check the value of that array by doing

element = array[i]

as the elements donā€™t contain their own x and y position, but the 2 dimensional array represents a grid usable to get the position by the indexes.

Try to think of it as a coordinate system, with x and y, similar to the command hero.moveXY(xCoordinate, yCoordinate)
where you move to the exact X and Y position, the array contains arrays which then contains values you need to check, but not the position itself, thatā€™s depending on where it is in the array. [x][y] or [y][x] (unsure how the 2 dimensional array is setup there)


Sadly i donā€™t use python myself, so i canā€™t be certain about the information Iā€™m giving you, but i hope that the additional information i gave is correct and useful.:sweat_smile:

3 Likes

@Shurutsue is spot on! For this problem we want to use the index of the arrays. You can do it with a for loop or a while loop. When using an index in a for loop, it helps to use the range(len(array)).
The first for loop will isolate the row in this case so in the second for loop you can work through each position for each row. The combination of that row and position on hero.grid is what you want to compare to 1.

2 Likes

see Sleepwalkers help and the link visualisation - this is the code behind the @Shurutsue explanation.

2 Likes

All right, Iā€™ll give it a shot. Iā€™d been doing a little thinking along those lines since I posted. Thanks much!

1 Like