[SOLVED] Stuck on Mega-Munchkin Attacks 2

The continue of the discution from this topic.
Stuck on Mega-Munchkin Attacks

Still got the error:

You get the error because Ivy dies.
Try to place flags and command her to move to a flag’s posision in order to mive to a fixed location.
Do you need any more assistance at this level?

And… She still dies:

It would be much simpler to just determine the distance and then react accordingly. Here’s the basic structure that will do this:

determine if there is both an enemy and ivy, if true then
    determine distance
    if distance is less than 10, then
        moveXY on a diagonal, 10 meters away
    otherwise
        attack 
1 Like

I did before num 2 (not 1) was created:

    distance = Ivy.distanceTo(enemy)
    flag = hero.findFlag("green")
    if distance <= 5:
        hero.command(Ivy, "move", {"x": flag.pos.x, "y": flag.pos.y})
    else:
        hero.command(Ivy, "attack", enemy)

This is what I was trying to say.

On this line also check if the flag exists.

At this point, I think trying to use the flag is just confusing things. As Andrei mentioned, the error was caused because Ivy died…to resolve this, use an if statement to test if there is ‘Ivy’.

Then, use the structure I shared as a temple and write the code that matches the statements.

1 Like

I recomand @Psychzander to use flags so Ivy will not become stuck in a corner, but with the structure I agree that it is the one to use.

I tried flags:

while True:
        #.......
        if flag:
        flagdistance = Ivy.distanceTo(flag)
        for i in range(flagdistance):
            hero.command(Ivy, "move", {"x": flag.pos.x, "y": flag.pos.y})
        hero.removeFlag(flag)

Istead of all of this you only need this

Now, she doesnt attack because of the flag :frowning:

Check the distance and only if the distance <= 5 mive to flag’s posision. Try to use the scheme that @dedreous showed you and add to the if distance <= 5 an and flag.

Here we do not post solutions. So if you completed the level you can ( and should ) delete the code that you previously posted.