Help On Levels In Mountain

My code for zoo keeper:

# Protect the cage.
# Put a soldier at each X.
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}

# 1. Collect 80 gold.
if hero.gold < 80:
    item = hero.findNearestItem()
    hero.move(item.pos)
# 2. Build 4 soldiers.
for i in range(4):
    hero.summon("soldier")
# 3. Send your soldiers into position.
while True:
    friends = hero.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            # Command friend to attack.
            pass
            hero.command(friend, "attack", enemy)
        else:
            # Command friend to move to point.
            pass
            hero.command(friend, "defend", point)
            hero.command(friend, "defend", point)
            hero.command(friend, "defend", point)
            hero.command(friend, "defend", point)

you only need onecommand

1 Like

You only need one command for commanding the friend to defend the point.

My hero just keeps on trying to summon soldiers and the soldiers do nothing

if you need a pass, use it after the command

1 Like

Here instead of using an if statement, use a while statement. So while your hero’s gold is less than 80, he will collect gold.

1 Like

without collecting coins

I summoned all okay but not defending

delete this it stops yu from commanding

2 Likes

check if there is and item
and just as @abc said use a while loop

1 Like

hey, wait a moment, I think theres something else wrong

YAY! Thank you for helping me put everything together and it worked!

2 Likes

i bet someone needs to click a solution checkbox lol

clickthe tickbox next to the post that helped most

2 Likes

I can’t for some reason

Ok, help with hunting party now please

while True:
    friends = hero.findFriends()
    # Use for-loop and for each friend:
    for friend in friends:
        # If they see an enemy then command to attack.
        enemy = hero.findNearestEnemy
        if enemy:
            hero.command(friend, "attack", enemy)
        # Command to move east by small steps.
        hero.command(friend, "move", {'x' + 1, 'y'})

you need to make it so your friends find their nearest enemy

your telling your friends to move x plus one, but what x are they going to move apon same for the y cordinates

1 Like

How to make friends find nearest enemy and what do you mean for your second post

Do you just do friend.findNearestEnemy or something

yes