Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Mind the trap. Help ME!

I cant figure out this level this is my code

while True:
    flag = hero.findFlag()
    enemy = hero.findNearestEnemy()
    
    if flag:
        # Pick up the flag.
        hero.pickUpFlag(flag)
        hero.say("I should pick up the flag.")
    elif enemy:
        # Only attack if the enemy distance is < 10 meters
        if self.distanceTo(enemy) < 10:
            hero.attack(enemy)

please Help!
1 Like

can you be a little more specific

1 Like

It says i ran out of time

1 Like

the code looks fine you just need to put the flags in the right place

1 Like

try faster boots Jet 531

1 Like

where do i put them HELP ME!!!

1 Like

ok one sec Jet531. I will check your code

1 Like

place the flag near the ogres like close to the middle of their circle

1 Like

This wuld only work if you have the right armour

1 Like

i meant to say would

1 Like

did you pass it Jet531

1 Like

I just needed the right armor thank you Andevar000

2 Likes

you are welcome Jet531

3 Likes
# Ты должен убедиться, что ты атакуешь врагов, которые находятся рядом с тобой!

while True:
    flag = hero.findFlag()
    enemy = hero.findNearestEnemy()
    if flag:
        # Возьми флаг.
        hero.pickUpFlag(flag)
        #hero.say("Я должен взять флаг.")
        hero.say("Я должен взять флаг.")
    elif enemy:
        # Атакуй врага, если он находится на расстоянии < 10 метров
        if (hero.distanceTo(enemy)< 10):
            if hero.isReady("cleave"):
                hero.cleave(enemy)

Почему код неправильный,в чем проблема?

1 Like

This line should not have parenthesis around the entire method.
Эта строка не должна иметь круглых скобок вокруг всего метода.
It should be:
Должен быть

if hero.distanceTo(enemy)< 10:
1 Like

i need help on the level

Hi hehe, if you need help with a level, please post your code; formatted. (see topic: How to Post Your Code With Radiant, Harmonious Formatting) And explain what the problem is.
Thanks
Danny

this is my code:

while True:
green = hero.findFlag(“green”)
black = hero.findFlag(“black”)
nearest = hero.findNearestEnemy()

if green:
    hero.pickUpFlag(green)
elif black and hero.isReady("cleave"):
    hero.pickUpFlag(black)
    # Cleave!
    hero.cleave(nearest, enemy)
elif nearest and hero.distanceTo(nearest) < 10:
    # Attack!
    enemy = hero.findNearestEnemy()
    hero.attack(enemy)
    pass

i can’t defeat the big ogres

Hi hehe, sorry for the late reply.
The only problem I see in your code is

hero.cleave() only has one parameter (thing in the bracket), if you get rid of “enemy” and the comma it will work.
I did it with your code (with that change) and you can win only using cleave, you just have to time it right. When all the ogres have come into the circles.
When you say “big ogres”, is your level different from mine? Mine only has small ogres (munchkins), is that what you meant when you said “big ogres”
Danny

A few things. Oddly enough, the method cleave doesn’t really need a parameter, but it helps with targeting. It will run the code with two parameters, but seems to take the first variable. One thing to keep in mind, when you check for one variable, you don’t want to switch the variable after it.

    elif nearest and hero.distanceTo(nearest) < 10:  # checking for nearest
        # Only attack if the enemy distance is < 10 meters
        enemy = hero.findNearestEnemy() # look for a new enemy after checking nearest
        hero.attack(enemy)

Even as it is, you code will pass the level. You can’t defeat them because your hero is dying? I’m wondering if you need better armor.