"Hunter Valley" needs additional introductions?

Hi Community :slight_smile:

Im at the Hunter Valley stage, I feel the code used in this stage should be explained a bit more. There is no explanation of what the “step” parametre used in the functions is. Also there is used different brackets [0] in this stage, which is not explained. I can’t remember += has been used before and routeIndex.

I haven’t focused that much on completing the stage as I rather understand every detail about the code first.

Maybe im just stupid I don’t know, but I feel like an introduction to some of the things would be great.

I don’t know if anything about step or any of the others you mentioned are explained in the “Hints” section since I haven’t played this level in a while, but they could be.
You mentioned something about different brackets. Square brackets (or these: [ ]) are used in Python for usage of arrays. For instance:

exampleArray = [x, y, z] # x, y, and z are units within exampleArray

firstInArray = exampleArray[0] # this will return x, the first unit in the array. See link below for information about using 0 and not 1 for the first unit

+= is a thing in Python used to increment indexes like the routeIndex you also mentioned. For example, let’s say you’re trying to fight ogres without using findNearestEnemy(). You’ve got enemies and enemyIndex defined and all…What now?

enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies): # before you ask, len(thangs) is just the length of an array. For the exampleArray above, len(exampleArray) = 3
    enemy = enemies[enemyIndex]
    if enemy:
    enemyIndex += 1 # now enemyIndex is one more than its original value, so now enemy is enemies[enemyIndex] as usual, but enemyIndex is 1 (or 2, or whatever depending on the number of times the loop runs)
1 Like

This is level is confusing at first if you don’t understand what “step” does. The answer is: its just a variable. You can call it whatever, even your first name and it will work. In the while loop, you pass a certain number, for example, 8.

As you can see, in both moveUpRight and moveDownRight, both code have you adding x + step, or in this 8. This means everytime you call the function, you will move 8 meters to the right.

However, in moveUpRight, you add step and in moveDownRight, you subtract step. This is because when you subtract step from y, you are going in a downwards direction. Combine the x & y and you see that your hero will move in a downwards motion while also move right, or a downward diagonal.

Similar with moveUpRight, when you add step to y, combined with the x, you are moving in an upright direction.

Bottom line to remember is:

If you add a positive number to x it means move right.

If you subtract a number to x it means move left.

If you add a positive number to y it means move up.

If you subtract a number to y it means move down.


Thank you for your answers Hellenar and _TD_RodYT

There is close to zero explanation in “hints” so there is no help there, I checked before posting. I check hints often if I have issues with the stage.

I looked up arrays and from my understanding it stores a collection of values, where a variable only holds one value.
So if you would need a collection of values like a lot of numbers in your code an array is much better for that (correct me if im wrong).

Thanks for posting the link with 0-based indexing.

Got some problems understanding the index thing, from my understanding its used to find positions in strings and arays,

In the code the example you make with len and exampleArray makes perfect sense that it is 3, what is (thangs) btw ?

But in the while true loop:

EnemyIndex is lesser than the length of the enemies variable ? How should that be understood ? In the array you could see there where 3 values of data. And the length would be 3. What is the length of the enemies variable ?

enemies = hero.findEnemies()
enemyIndex = 0
while enemyIndex < len(enemies):

Yea I totally missed that, guess all the other index and array stuff made me confused. I also used that on a lot of other stages :slight_smile:

1 Like

Lets say there are 3 enemies alive. So enemies.length is 3. enemyIndex is 0. The loop is saying that while enemyIndex or 0 is less then enemies.length, or 3, continue to loop. Of course, 0 will always be less than three. That’s where the enemyIndex += 1 part comes in. Every loop, enemyIndex will increase by 1. So the first loop enemyIndex is 0. The second loop, enemyIndex will be 1. The third loop, enemyIndex is 2. However, on the fourth loop, enemyIndex is now 3. According to the while loop statement, 3 is not < 3, so it jumps out of the loop.


That makes sense, thank you

1 Like