I need help,I forgot the distance method, i also need help on Rich Forager

help please

pls,someone

Can you be more spesific than just saying help.

3 Likes

@calvin you can look back at you previous levels. but here it is:

Python:

enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance <= 3:
    hero.attack(enemy)

or JS:

var enemy = hero.findNearestEnemy();
var distance = hero.distanceTo(enemy);
if (distance <= 3) {
    hero.attack(enemy);
}

I think that’s right. I just started working on JS today lol

1 Like

And for the signs:

→ <= less than or equal to
→ == equal to

→ >= greater than or equal to

→ != not equal to

→ % modulous [if you don’t know this, ignore it]

4 Likes

yeah, I don’t think you can do that one until code book IV

1 Like

mhm. … yup (20charsssssssaleready)

i also needed help on rich forager

Make another topic on that.

2 Likes

@thebagel it is fine if @calvin makes this a level help topic. So please go ahead and give us your code @calvin and make sure to press the </> before you do.

1 Like

Oh, ok! sry about that.

1 Like

Can u show us ur code? plz format it 2

1 Like

@calvin Pythonor javascript?

1 Like
# Use "if" and "else if" to handle any situation.
# Put it all together to defeat enemies and pick up coins!
# Make sure you bought great armor from the item shop! 400 health recommended.

while True:
    flag = hero.findFlag()
    enemy = hero.findNearestEnemy()
    item = hero.findNearestItem()

    if flag:
        # What happens when I find a flag?
        hero.pickUpFlag(flag)
    elif enemy:
        # What happens when I find an enemy?
        hero.attack(enemy)
    elif item:
        # What happens when I find an item?
        if (item) distance <=6:
        hero.moveXY(item.pos.x,item.pos.y)
        

all you need to do is press submit, and use the flags in de bottom left corner to guide your hero to get all the coins.

2 Likes

Your code is perfect

2 Likes

If it works please delete it @calvin

2 Likes