[Solved] Underground business i need help

i need help with underground business. here is my code: 55 PM

i can’t figure out what’s wrong.

You do not need to put pet.on("spawn", onSpawn) in a while-true loop. It automatically loops itself.

okay but now it has two errors:36 AM

What is gold? Try using hero.gold. Also be sure to use >= because there could be more than 300 gold (>= means greater than or equal to), or else you will be assigning 300 to the variable gold.
I don’t quite understand the enemy issue, but unless you don’t have any glasses equipped, it should be working.

Also a little side note: I suppose that you should let the pet move to each corner of the dungeon because it is magnetic and attracts items, and there is more than one type of item to collect.

thanks! it worked! (it has to be 20 characters)

I can’t get 300 coins, only 150 coin. Do anyone know the resolution?

Accumulate 300 gold and escape from the dungeon.

def onSpawn(event):
while True:
# Send the pet to walk around the dungeon:
pet.moveXY(19,35)
pet.moveXY(20,37)
pet.moveXY(21,32)
# Don’t forget to return it to the hero:
pet.moveXY(hero.pos.x, hero.pos.y)
pass

pet.on(“spawn”, onSpawn)

while True:
# Guard peasants:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# When you have 300+ gold move to the red mark:
if hero.gold >=300:
hero.moveXY(50, 34)
pass

1 Like

Did you get all the gold from the mimic, or did you not get any at all.

I only get 150 gold and don’t have any way to get all 300 gold. I don’t know why.

1 Like

Even if i let mimic run around, it is still 150 coin :frowning:
Anyone who can give me the correct code? Don’t instruction :frowning:

1 Like

for one you shouldn’t put it in a while loop.

1 Like

I have passed. Thank you all :)))

This level is weird. Why does this code not work:

def onSpawn(event):
    item = pet.findNearestByType("coin")
    if item:
        pet.moveXY(item.pos.x, item.pos.y)
        pet.moveXY(hero.pos.x, hero.pos.y)

This code makes the Mimic walk to the closed copper coins and go back to the hero only once. After that, it just stands there.

Problems:

  1. This is the solution suggested in the hints section, but it doesn’t work.

  2. I was thinking “duh, it needs to be looped”, but a) putting this in a while-True loop results in only one repetition (see below) and b) @Hellenar claimed:

    But, why would it loop automatically?

    And if it does/should, why doesn’t the mimic repeat its action?

  3. When the Mimic goes to the copper coins and then returns to the hero, the coins aren’t dragged along with it all the way - for some reason it leaves them behind after a few meters:

  • Without looping (it tries to retrieve only the lower set of coins, then stops):

  • …and with loop (it tries to retrieve both the upper and lower set of copper coins, then stops):

For the record, I have solved this level by just sending the Mimic in a circle using absolute coordinates.
My goal here is to understand A) why the other solution doesn’t work, and B) if it doesn’t work, why is it (misleadingly) shown in the hints section?

1 Like
pet.on("spawn", onSpawn)

Upon spawning, the pet automatically runs the function onSpawn. (not sure if this explanation will suffice)

I’m afraid not. When the pet spawns, the function is executed once (also, spawn happens only once). There is no command that would explicitly make it loop, is there?
Unless the .on event handler is a loop in and of itself - is it?

You only need to tell the pet to go around the dungeon. then make it come back.

Did you read this part that I wrote?

The code does not work because the mimic cannot see the other items. It cannot see through walls either.

1 Like