Mountain Mercenaries Help Required, PLEASE HELP!

Hi guys, I’m not exactly new around here but I have a problem with Mountain Mercenaries. It keeps saying: Line19 Your Hero Placerholder needs something to command.
Every reply, help and command are thanked.
My Code -

Gather coins to summon soldiers and have them attack the enemy.

loop:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.say(“I need coins!”)

# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
    self.say("I should summon something here!")
enemy = self.findNearest(self.findEnemies())
if enemy:
    # Loop over all your soldiers and order them to attack.
    soldiers = self.findFriends()
    soldierIndex = 0
    soldier = soldiers[soldierIndex]
    self.summon("soldier")
    self.command(soldier, "attack", enemy)
    # Use the 'attack' command to make your soldiers attack.
    #self.command(soldier, "attack", enemy)

It is clearly written in the FAQ how to

How do people still manage to use block-quotes?


Sorry for the little rant, here is your problem:

soldiers = self.findFriends()          #Is currently empty, no friends spawned yet
soldierIndex = 0
soldier = soldiers[soldierIndex]       #Tries to get the first entry of an empty list, soldier = None
self.summon("soldier")                 #If you would now call findFriends(), you would get a list with one entry
self.command(soldier, "attack", enemy) #As soldier is None your code fails

You should solve the level as intended. There is a line in the default-code that says "I should summon something here!" Use this place to summon your soldiers, it works best.

I did this but my soldiers won’t attack anything.

Gather coins to summon soldiers and have them attack the enemy.

loop:
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.say(“I need coins!”)

# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
    self.summon("soldier")
enemy = self.findNearest(self.findEnemies())
if enemy:
    # Loop over all your soldiers and order them to attack.
    soldiers = self.findFriends()
    soldierIndex = 0
    soldier = None
    soldierIndex += 1
    self.command(soldier, "attack", enemy)
    # Use the 'attack' command to make your soldiers attack.
    #self.command(soldier, "attack", enemy)

Once you have a loop:, everything in the loop needs to be indented by one tab or four spaces. Lines 2-4 are not.

You have a problem with your if enemy: section. You tell it to define soldiers as all friends, then soldierIndex as 0 and soldier as null, then add one to soldierIndex without having used either soldierIndex it or soldiers. At this point, you attempt to command a soldier you defined as none. This doesn’t work. You need a while- or for-loop.

Also, it’s going to be hard to summon enough soldiers without gathering coins. Replace self.say("I need coins!") with code to find coins.

I got mine to work using this code below. The kicker was using move and not moveXY and on top of that don’t try to use an array for coins, if you do you’ll waste time going from coin to coin instead of just grabbing what is closest.

[redacted, we don’t post correct code]

Please don’t post correct code–it takes the whole point out of the game.

2 Likes

You should use flags and attack. You can summon if there is a black flag and move for the green. You will also need to attack.

I agree. Could someone just hide the code so no one uses it?

I flagged it for moderation. The guys in charge should fix the problem. Have a great day!

Hi, I have similar problems. My soliders are just staying like my hero. Hero do not collect coins and soldiers are not attacking. Every help is welcomed.

 `while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    hero.say("I need coins!")
    if hero.gold < hero.costOf("soldier"):
        while hero.gold < hero.costOf("soldier"):
            items = hero.findItems()
            nearest = hero.findNearest(items)
            if nearest:
                hero.say(hero.distanceTo(nearest))
                hero.move(nearest.pos)
# If you have funds for a soldier, summon one.
    if hero.gold > hero.costOf("soldier"):
        hero.say("I should summon something here!")
        hero.summon("soldier")

    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = hero.findFriends()
        soldierIndex = 0
        if soldiers:
            hero.say("soldiers")
            while len(soldiers) > soldierIndex:
                soldier = soldiers[soldierIndex]
                if soldier:
                    hero.say("found one")
                    hero.command(soldier, "attack", enemy)
                    soldierIndex += 1

`

All I did was remove all hero.say() commands

first remove all of the say commands, you don’t need them, then change this

to this

        if soldiers:
            hero.say("soldiers")
            while len(soldiers) > soldierIndex:
                soldier = soldiers[soldierIndex]
                if soldier:
                    hero.say("found one")
                    hero.command(soldier, "attack", enemy)
                soldierIndex += 1

because you need to increase the index no matter if you found a soldier or not