Mounatin Mercenaries Error


#1

HELP PLEASE


#2

Do you not remember how to use a while-loop? If you do not, replay Mad Maxer and Cloudrip Commander. Those levels should jog your memory.


#3

That’s not the problem. the priblem is the “Line 19: tmp47[tmp48] is not a function”


#4

Hm, that’s no good. What glasses are you using?


#7

Not the twilight i am using the fine wooden glasses. my bad


#8

Ok now I am using the Twilight glasses and the error is fixed, but another popped up saying “Hero Placeholder needs somthing to command” on line 26: self.command(“soldier”, “attack”, enemy)


#9

Can you post the entirety of your code?

To format your code correctly please press the </> button in the Discourse toolbar or surround your code with 3 back ticks.

```
Code goes here.
```


#10
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos = item.pos
x = itemPos.x
y = itemPos.y

loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        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 = soldiers[soldierIndex]

        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
        self.command(soldier, "attack", target)

#11

You don’t define target. Do you mean “enemy”?


#12
# Gather coins to summon soldiers and have them attack the enemy
item = self.findNearestItem()
itemPos =  item.pos
x = itemPos.x
y = itemPos.y

loop:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.say("I need coins!")
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.say("I should summon something here!")
        self.summon("soldier")
    enemy = self.findNearestEnemy()
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
        self.command(soldier, "attack", enemy)



#13

I see a few problems. You define item once, but not again, so your hero will only pick up the nearest coin once. Also, you command only the first soldier to do anything.


#14

This is the line that has an error:

soldiers = self.findFriends()

#15

I think its just that I have crap gear. I bought a short sword and made the code so I just attacked, but I still die. You should just give me like 2600 gems and I will be good


#16

It’s basically out of the question to give you gems. We want you to progress on your own. Hitting us up for gems isn’t the best way to do this. You could always try simulating. Go here: http://codecombat.com/play/ladder/cavern-survival#simulate and hit the button that says “simulate”. You will get gems based upon how many you have done.

Out of curiosity, why are you wearing Wooden Glasses? You should have at least the Mahogany Glasses by now…


#17

I prefer the wooden glasses so I can use nearest enemy/nearest item. But now that I know how to use the nearest and enemies code, I will be using the twilight glasses


#18
# Gather coins to summon soldiers and have them attack the enemy


loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos =  item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
        self.command(soldier, "attack", enemy)

Now the problem is self.command(soldier, "attack", enemy)
It says: ‘Hero Placeholder needs something to command’


#19

soldiers is a indexed list.
It will contain the several values: soldiers[0], soldiers[1], soldiers[2], …
The length of the list is given by len(soldiers)
Since the index numbers start from 0, the last index will be len(soliders)-1

Example:

mylist = [5,6,7]
# the length of this list is len(mylist) = 3
# the elements are mylist[0] = 5, mylist[1] =6, mylist[2] =7

Now knowing all this you can write:

soldierIndex=0
while (soldierIndex < len(soldiers)):
    # do something with soldiers[soldierIndex]
    soldierIndex++

A faster way to write the same loop:

for i in range(len(soldiers)):
    # do something with soldiers[i]

The for structure automatically makes i go from 0 to len(soldiers)-1

Even faster

for soldier in soldiers:
    #do something with solider

Instead of complicating with the index, this for makes solider go from soliders[0] to soldiers[len(soldiers)-1]


#20
# Gather coins to summon soldiers and have them attack the enemy


loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos =  item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex = 0
        soldier = soldiers[soldierIndex]

        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
        self.command(soldier, "attack", enemy)

OK This is my code. Everything works but my soldiers don’t attack


#21

The code hint says:

# Loop over all your soldiers and order them to attack.

Look at my post above. No spoonfeeding


#22
# Gather coins to summon soldiers and have them attack the enemy


loop:
    items = self.findItems()
    item = self.findNearest(items)
    itemPos =  item.pos
    x = itemPos.x
    y = itemPos.y
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    self.moveXY(x, y)
    # If you have funds for a soldier, summon one.
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        # Loop over all your soldiers and order them to attack.
        soldiers = self.findFriends()
        soldierIndex += 1
        soldier = soldiers[soldierIndex]
        soldierIndex += 1
        myList = [5, 6, 7]
        # Use the 'attack' command to make your soldiers attack.
        #self.command(soldier, "attack", enemy)
for soldier in soldiers: 
    self.command(soldier, "attack", enemy)

Is this right? Because it still doesn’t work


Hunting Party Help!