[UnderGround Business] Can't collect 300 coin. (Only 150)


#1


I don’t know why i can’t collect enough 300 coins, please help me to resolve it?

Accumulate 300 gold and escape from the dungeon.

def onSpawn(event):
    goldCoin = pet.findNearestByType("coin")
    if goldCoin:
    # Send the pet to walk around the dungeon:
        pet.moveXY(goldCoin.pos.x, goldCoin.pos.y)
    # 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

#2

Please format your code according to the FAQ.


#3

Please, read that instruction again.

Your code makes the pet find the nearest coin, go there and return. It’s all.


#4

I have changed my code but it still return back 150 coin :frowning:#
Accumulate 300 gold and escape from the dungeon.

def onSpawn(event):
    pet.moveXY(32, 56)
    pet.moveXY(63, 55)
    pet.moveXY(73, 14)
    pet.moveXY(43, 7)
    pet.moveXY(25,8)
    # Don't forget to return it to the hero:
    pet.moveXY(hero.pos.x, hero.pos.y)
   
    # 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, 35)
    pass

#5

the coins are being dragged BEHIND the pet
even if the pet moves to your position, not all the coins get collected.
also, u know the peasants mine 5 coins per second, so you can wait for 30 seconds and get the other 150 coins
#1 rule about being a coder:
be creative :wink:


#6

I don’t understand what are you talking? Please explain a little?


#7

The coins are attracted my the mimic like a magnet, but it won’t perfectly stick on to it.


Error in Underground Business
#8

so how you did before?


Error in Underground Business
Error in Underground Business
#9

You should try looking at your mimic move around the dungeon because you have to aim so it walks near the coins.
Did you try @Bryukh’s hint?


#10

Looks like you lost “while true” part. Also don’t forget to assign an event handler.


#11

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:


#12

I have done. Thank you all


#13

Good job @le_thi_ngoc_le