Salted Earth - Please Help

while True:
enemy = hero.findNearestEnemy()
if enemy.type == “munchkin” or enemy.type == “thrower”:
hero.attack(enemy)
item = hero.findNearestItem()
# Check the item type to make sure the hero doesn’t pick up poison!
# Look for types: ‘gem’ and 'coin’
if item.type == “gem” or item.type == “coin”:
hero.move(item.pos)
This is my code for this level. For some reason it doesn’t work giving me the error : "TypeError: Can’t read protected property : move
Can someone help me with this?

1 Like

Hey! Can you format your code please? Highlight it and press the " < / > " button before posting. Or you can put 2 backticks before and after your code.

I believe its 3 before and after.

Either way works mate ^^

while True:
    enemy = hero.findNearestEnemy()
    if enemy.type == "munchkin" or enemy.type == "thrower":
        hero.attack(enemy)
    item = hero.findNearestItem()
    # Check the item type to make sure the hero doesn't pick up poison!
    # Look for types: 'gem' and 'coin'
    if item.type == "gem" or item.type == "coin":
        hero.move(item.pos)

Like this?

1 Like

Chnaces are your not wearing the right equipment. You need the shoes that allow the property of move. Try using moveXY their might be a chance thats what your current shoes can access. And yes thats much better.:grin:

You forgot to add x and y. it should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy.type == “munchkin” or enemy.type == “thrower”:
hero.attack(enemy)
item = hero.findNearestItem()
# Check the item type to make sure the hero doesn’t pick up poison!
# Look for types: ‘gem’ and 'coin’
if item.type == “coin” or item.type == “gem”:
hero.moveXY(item.pos.x, item.pos.y)

Eventually the hero will be able to access boots that have move property, which is good if the hero wants to follow moving objects as it does not always return a fixed coordinate. (Also good for just moving to coins, gems or potions if you want to save time and space.)
Also try not to revive dead threads in the future :slight_smile:

Is This JavaScript? If’s usually have brackets and parenthesis around them @Kid_Midas

I am having the same problem as @Kid_Midas is. Halp :confounded:

Did you check your equipment to see if the boots you’re currently equipped with have the move property? There is going to be two different ways to write the code for this; one is for move property and the other is for the moveXY property. It just depends on which boots you’re using.

BTW, the previous posts are in Python, not Java.

By the way, if you do have boots with move, then they have to be equipped.

By move so you mean “MoveXY” or Move right/left/up/down?

@agarionotpro

Using the moveXY method is different than the move method.

Using moveXY means, go to this coordinate and don’t do anything else until you get there.

Using the move method means take a single step toward a position and then iterate through the code again looking for something else to do. If there is nothing else to do, then take another single step toward that position again. This is particularly handy when moving to a position that is not constant (like another character that is moving).

You need to equip with boots that offer the move method if you’re going to use it.

`