[Adventurer] Double Agent


#1

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.


#2

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


#3
  1. Merged. Thanks!

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


#4

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


#5

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


#6

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)

#7

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


#8

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)

#9

Don’t redefine pet

20cahrs


#10

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)

#11

passage doesn’t have pos property.


#12

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.


#13

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.


#14

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