Salted Earth - Please Help


#1

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?


#2

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.


#4

I believe its 3 before and after.


#5

Either way works mate ^^


#6
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?


#7

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:


#8

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)


#9

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:


#10

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


#11

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


#12

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.


#13

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


#14

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


#15

@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.

`