Need help with "Sarven Siege"

thx it worked despite github’s suggestion

github is one not working

I am trying to make a force of griffin-riders and paladins and just focus on one arrow-tower, but my paladins won’t heal the arrow-tower.

# Defend your towers in this replayable challenge level!
# Step on an X if you have 20 gold to build a soldier.
summonTypes = [ "griffin-rider", "paladin", "griffin-rider"]
def summon():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)

def command():
    target = hero.findNearestEnemy()
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    
    if enemy:
        
        for friend in hero.findByType("griffin-rider"):
            hero.command(friend, "defend", {"x": 78, "y": 22})
        for friend in hero.findByType("paladin"):
            if friend.canCast("heal"):
                towers = hero.findByType("arrow-tower")
                tower = friend.findNearest(towers)
                hero.command(friend, "cast", "heal", tower)
            else:
                hero.command(friend, "defend", {"x": 78, "y": 22})

while True:
    summon()
    command()
    enemy = hero.findNearestEnemy()
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

my hero won’t move

my code:

Defend your towers in this replayable challenge level!

Step on an X if you have 20 gold to build a soldier.

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

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

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)

def summonSoldier(lenlist):
soldier = ‘archer’
if hero.gold > hero.costOf(soldier):
hero.summon(soldier)
indexSoldier += 1

commands attack

def commandSoldiers():
for soldier in hero.findFriends():
enemy = hero.findNearestEnemy()
if enemy and soldier.type == ‘archer’:
hero.command(soldier, “attack”, enemy)

list = [‘soldier’, ‘archer’]
indexSoldier = len(list)
while True:
if hero.now() > 10:
summonSoldier(len(list))
commandSoldiers()
items = hero.findItems()
if (len(items) > 0):
pickUpNearestItem(items)
else:
enemy = hero.findNearestEnemy()
attack(enemy)

I can’t figure out how to format it. :frowning:

Hi @NoNoSquare , please could you quickly read this topic so that you can post your code (from codecombat) with indentation (spaces) so I can copy it into codecombat without having to put in all the spaces myself.

is this good?

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


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


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)


def summonSoldier(lenlist):
    soldier = 'archer'
    if hero.gold > hero.costOf(soldier):
        hero.summon(soldier)
        indexSoldier += 1


# commands attack
def commandSoldiers():
    for soldier in hero.findFriends():
        enemy = hero.findNearestEnemy()
        if enemy and soldier.type == 'archer':
            hero.command(soldier, "attack", enemy)


list = ['soldier', 'archer']
indexSoldier = len(list)
while True:
    if hero.now() > 10:
        summonSoldier(len(list))
    commandSoldiers()
    items = hero.findItems()
    if (len(items) > 0):
        pickUpNearestItem(items)
    else:
        enemy = hero.findNearestEnemy()
        attack(enemy)

yes much better @NoNoSquare

The reason your hero is not moving is because you have not “called” you moveTo function at any point. You’ve written it out like this:
def moveTo(position, fast=True):
But to actually make the contents of the function run, you need to put it inside the while loop at some point like this:
moveTo(position, fast=True):
But with a proper position inside.
Danny

when I do that it says “Line 13: TypeError :TypeError”

Define position were is that

I don’t understand what you mean by that.

right here

Were did you define position