Sarven Siege Error Help

<<< def moveTo(position, fast=True):
if (hero.isReady(“jump”) and hero.distanceTo > 10 and fast):
hero.jumpTo(position)
else:
hero.move(position)

pickup coin

def pickUpNearestItem(items):
nearestItem = hero.findNearest(items)
if nearestItem:
moveTo(nearestItem.pos)

add soldier

summonTypes = [‘archer’,
‘peasant’]

def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)

def findNearest(index):
top = False
left = False
if (index == 0):
top = True
left = True
elif (index == 1):
top = True
elif (index == 3):
left = True
items = hero.findItems()
for item in items:
if (item.pos.y > 66 and top and left and item.pos.x < 76):
return item
elif (item.pos.y < 66 and not top and left and item.pos.x < 76):
return item
elif (item.pos.y > 66 and top and not left and item.pos.x > 76):
return item
elif (item.pos.y < 66 and not top and not left and item.pos.x > 76):
return item
return None

commands attack

def commandTroops():
index = 0
for friend in hero.findFriends():
if friend.type == ‘peasant’:
item = findNearest(index)
index += 1
if item:
hero.command(friend, ‘move’, item.pos)
else:
enemy = hero.findNearestEnemy()
archers = hero.findFriends()

        if enemy:
            hero.command(archers, "attack", enemy)

def attack(target):
if target:
if (hero.distanceTo(target) > 10):
moveTo(enemy.pos)
elif (hero.isReady(“bash”)):
hero.bash(enemy)
elif (hero.isReady(“power-up”)):
hero.powerUp()
hero.attack(enemy)
elif (hero.isReady(“cleave”)):
hero.cleave(enemy)
else:
hero.attack(enemy)

while True:
summonTroops()
commandTroops()
enemy = hero.findNearestEnemy()
attack(enemy>>>

I would like to make a peasant who will walk around and get me gold. Then, I will get some troops to help. But that irritating duck comes up and says I can’t command “arrow-tower” WTF

Crap IDK how to format

def moveTo(position, fast=True):
    if (hero.isReady("jump") and hero.distanceTo > 10 and fast):
        hero.jumpTo(position)
    else:
        hero.move(position)

def pickUpNearestItem(items):
    nearestItem = hero.findNearest(items)
    if nearestItem:
        moveTo(nearestItem.pos)

summonTypes = ['archer',
'peasant']

def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)

def findNearest(index):
    top = False
    left = False
    if (index == 0):
        top = True
        left = True
    elif (index == 1):
        top = True
    elif (index == 3):
        left = True
        items = hero.findItems()
    for item in items:
        if (item.pos.y > 66 and top and left and item.pos.x < 76):
            return item
        elif (item.pos.y < 66 and not top and left and item.pos.x < 7):
            return item
        elif (item.pos.y > 66 and top and not left and item.pos.x > 7):
            return item
        elif (item.pos.y < 66 and not top and not left and item.pos.x > 76):
            return item
        return None

def commandTroops():
    index = 0
    for friend in hero.findFriends():
        if friend.type == 'peasant':
            item = findNearest(index)
            index += 1
    if item:
        hero.command(friend, 'move', item.pos)
    else:
        enemy = hero.findNearestEnemy()
        archers = hero.findFriends()
    if enemy:
        hero.command(archers, "attack", enemy)
def attack(target):
    if target:
        if (hero.distanceTo(target) > 10):
            moveTo(enemy.pos)
        elif (hero.isReady("bash")):
            hero.bash(enemy)
        elif (hero.isReady("power-up")):
            hero.powerUp()
            hero.attack(enemy)
        elif (hero.isReady("cleave")):
            hero.cleave(enemy)
        else:
            hero.attack(enemy)

while True:
    summonTroops()
    commandTroops()
    enemy = hero.findNearestEnemy()
    attack(enemy)

Ok I think this is better
It took me forever to do this

1 Like

That is not properly formatted @Falcons118. Python requires indentation.

yeah I know… let me do them

In your reply, press these buttons:

Ctrl Shift C

There should be these words:

type or paste code here

Copy your code from Codecombat and paste it here. Then delete the “type or paste code here”.

Once you post your code, can you also take a screenshot and upload it here @Destroyer636?

I meant for you to format your code here, and take a screenshot of the error, and screenshot your equipment.

so was my formatting incorrect?
I edited it

I think I found the problem. Is your problem that it won’t complete the level? It says incomplete because you have to submit it for it to work. You have to be crafty with it though, this level gets hard overtime.

I have an error it says can’t command arrow tower wtf

yeah, you can’t command towers. if you are comanding a soldier, make sure the friend’s type is equal to soldier, or just make sure the friend’s type is not equal to tower.

Please don’t use swear words, even in abbreviation.

Do this

if friend.type != "Arrow Tower"
 __command code here____
4 Likes