[Adventurer] Double Agent

Mountain level here: Double Agent

The mastery level about usage of trim. There is only one safe passage. Listen to silence in the agent’s message to find which one.

4 Likes

I was able to complete level.

A few things:

  1. I think the last comment got duplicated:

    The hero follows by the pet.The hero follows by the pet.

(fixed in grammar patch)

.2. When my hero follows the pet, he walks off the screen and then returns. I also get an error when this happens. (See message)

Submitted a grammar patch

1 Like
  1. Merged. Thanks!

  2. I see. I fixed it with a “hack”. Could you check it please?

1 Like

humm it seems to still be there. I sent you my code in a message.

2 Likes

I suppose it’s a problem with the typo in your code. Please check DM.

3 Likes

Level says Line 26: TypeError: Can’t read protected property: move, I have no idea what this means but I have Boots of Leaping equipped so hero.move(somewhere.pos) should not be an issue. My code is shown below.

# Count the number of trailing and leading whitespaces.

# This function returns the coordinates of the n-th passage.
def passagePosByNum(n):
    return {"x": 60, "y": n * 12 + 8}

def onHear(event):
    # The original message.
    message = event.message
    # Trim the message:
    newMessage = message.trim()
    # The hidden number is the difference of lengths:
    number = len(message) - len(newMessage)
    # Use passagePosByNum to find the passage to enter:
    passage = passagePosByNum(number)
    # Move the pet to the entrance of the passage:
    pet.move(passage.pos)
    # Move the pet to the left edge of the map:
    pet.moveXY(pet.pos.x - 58, pet.pos.y)

pet.on("hear", onHear)

# The hero should follow the pet.
while True:
    hero.move(pet.pos)
1 Like

pet doesn’t have the method move. Only moveXY. For threads (event handlers) errors are shown in the wrong place.

1 Like

Now it says Cannot read property ‘on’ of undefined.

# Find the hidden number in the agent's message to escape.
# Count the number of trailing and leading whitespaces.

# This function returns the coordinates of the n-th passage.
def passagePosByNum(n):
    return {"x": 60, "y": n * 12 + 8}

def onHear(event):
    # The original message.
    message = event.message
    # Trim the message:
    newMessage = message.trim()
    # The hidden number is the difference of lengths:
    number = len(message) - len(newMessage)
    # Use passagePosByNum to find the passage to enter:
    passage = passagePosByNum(number)
    # Move the pet to the entrance of the passage:
    pet.moveXY(passage.pos.x, passage.pos.y)
    # Move the pet to the left edge of the map:
    pet.moveXY(pet.pos.x - 58, pet.pos.y)

pet.on("hear", onHear)

# The hero should follow the pet.
while True:
    pet = hero.findNearest(hero.findFriends())
    if pet:
        hero.moveXY(pet.pos.x, pet.pos.y)
1 Like

Don’t redefine pet

20cahrs

1 Like

Cannot read property ‘x’ of undefined
wat???

# Find the hidden number in the agent's message to escape.
# Count the number of trailing and leading whitespaces.

# This function returns the coordinates of the n-th passage.
def passagePosByNum(n):
    return {"x": 60, "y": n * 12 + 8}

def onHear(event):
    # The original message.
    message = event.message
    # Trim the message:
    newMessage = message.trim()
    # The hidden number is the difference of lengths:
    number = len(message) - len(newMessage)
    # Use passagePosByNum to find the passage to enter:
    passage = passagePosByNum(number)
    # Move the pet to the entrance of the passage:
    pet.moveXY(passage.pos.x, passage.pos.y)
    # Move the pet to the left edge of the map:
    pet.moveXY(pet.pos.x - 58, pet.pos.y)

pet.on("hear", onHear)

# The hero should follow the pet.
while True:
    hero.moveXY(pet.pos.x, pet.pos.y)
1 Like

passage doesn’t have pos property.

1 Like

So then it would be pet.moveXY(passage) instead of pet.moveXY(passage.pos.x, passage.pos.y)?

I tried using pet.moveXY(passage) and now it says I have an error with hero moving to pet.pos. I’ve used both hero.moveXY(pet.pos.x, pet.pos.y) and hero.move(pet.pos) in a while loop and it tells me that moveXY takes only undefined argument and should have type number but got type object.

Here is my current code if you need more information.

# Find the hidden number in the agent's message to escape.
# Count the number of trailing and leading whitespaces.

# This function returns the coordinates of the n-th passage.
def passagePosByNum(n):
    return {"x": 60, "y": n * 12 + 8}

def onHear(event):
    # The original message.
    message = event.message
    # Trim the message:
    newMessage = message.trim()
    # The hidden number is the difference of lengths:
    number = len(message) - len(newMessage)
    # Use passagePosByNum to find the passage to enter:
    passage = passagePosByNum(number)
    # Move the pet to the entrance of the passage:
    pet.moveXY(passage)
    # Move the pet to the left edge of the map:
    pet.moveXY(pet.pos.x - 58, pet.pos.y)

pet.on("hear", onHear)

# The hero should follow the pet.
while True:
    hero.moveXY(pet.pos.x, pet.pos.y)

Somehow method hero.moveXY(pet.pos.x, pet.pos.y) works for me in Passing Through but not here.

1 Like

moveXY requires two arguments. Looks like you don’t understand object literals (I’m not trying to offend you). passage is an object with two properties x and ypos isn’t some magic variable or a function. Units and items have a property pos which has x and y properties. Try to return and revise levels about pos properties and movement in the Desert.

3 Likes

Thank you so much @Bryukh, I beat the level! :smile:

2 Likes

I managed to beat this level but i did not solve it how i was supposed to. i just had the pet move to the side and followed it. even when the seed for submiting meant that the path i went down had ogres for some reason i still suceeded. also if your seed is the safe path in the middle my code works heres how i had the pet move .

pet.moveXY(2, pet.pos.y)

after that i just moved to the pets pos

@Tv264, If you would like to explore the level further and learn how to solve it, go ahead and post your code (properly formatted)…we’d be glad to help out.

1 Like

Do not post your code @Tv264 unless you want help to figure out the correct solution because we do not allow solutions on the forum because others can use the code and cheat at the level.

1 Like