Help with Summits Gate!

I was trying to code the soldiers to attack the catapults, but there’s an error:

Line 29: Argument error: Target a unit.

This is my code so far:

# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
        lowestFriend = friend
    return lowestFriend

def destroyCatapults():
    catapult = hero.findByType("catapult", hero.findEnemies())
    for friend in friends:
        if friend.type == "soldier":
            hero.command(friend, "attack", catapult)
        elif friend.type == "archer":
            hero.command(friend, "attack", enemy)

while True:
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    catapult = hero.findByType("catapult", hero.findEnemies())
    # Paladin Healing
    mostHurt = lowestHealthPaladin()
    for friend in friends:
        if friend.type == "paladin":
            if hero.health < hero.maxHealth / 1.5:
                hero.command(friend, cast, "heal", hero)
            else:
                hero.command(friend, "cast", "heal", mostHurt)
    destroyCatapults()

‘enemy’ doesn’t exist

I legit have no idea with those codes lol, as I didn’t touch CC for 4 months.

But, in the code below you’ve written, enemy isn’t defined. This problem can be solved using “enemy” as a parameter taken as an argument later.

def destroyCatapults(enemy): # write 'enemy' as parameter
    catapult = hero.findByType("catapult", hero.findEnemies())
    for friend in friends:
        if friend.type == "soldier":
            hero.command(friend, "attack", catapult)
        elif friend.type == "archer":
            hero.command(friend, "attack", enemy)

for friend in friends:
        if friend.type == "paladin":
            if hero.health < hero.maxHealth / 1.5:
                hero.command(friend, cast, "heal", hero)
            else:
                hero.command(friend, "cast", "heal", mostHurt)
        destroyCatapults(friend.findNearestEnemy()) # indent this, and
# pass enemy as 'friend.findNearest'

P. S. @moonwatcher348 correct me if my code won’t work, as I solve problems without checking it in game xD

I also solve problems like that .-. I haven’t looked at coco levels in like 10 years (2 months, if not more) xd and you don’t need to pass enemy, just define it in the function -_-

this needs to be

catapult = hero.findNearest(hero.findbyType("catapult",hero.findEnemies()))

cus find by type retuns a array, while find nearest returns a varible, in this case a enemy, cuz u cant attack a array unless u use a for loop.

3 Likes

Oh I forgot to correct that for him, yeah I’ve forgot like a lot for CC

1 Like

well ,can a catapult be a friend, or he/she cast raise dead lol

Or use this also
catapult = hero.findByType("catapult", hero.findEnemies())
catapult = hero.findNearest(catapult)

1 Like

why over complicate, also, there is no friendly catapults in summit gate

1 Like

It’s not complicate, it’s easier to people who can’t write cat=hero.findNearest(hero.findByType(“catapult”,hero.findEnemies())) really fast. I’m pretty sure it’s easier to understand it when it’s a few lines, like Vectors in Skating Away.
And I think he meant that you can cast raise-dead near dead catapults and they will become friends.

1 Like

ohhhh, yeah, that’s true, and yeah, I guess some people just don’t type very well .-.

1 Like

Then the catapult can attack the beam tower lol

No, it cant because it cant see through the walls

1 Like

Oh, yea :grin: :grin: :grin:
yea, your right

It can “see” through, it just can’t fire xd

1 Like

Wait…guys, we are a little bit getting off the topic…
Is @person1 active now? I can give he some strats

1 Like

or check the teams “ogres” :smiley:

1 Like

Yeah, we can do this too

Guys:
the easiest way:

enemies = hero.findEnemies()
for enemy in enemies:
    if enemy.type == 'catapult':
        #do attack

you can add a while loop to check if the enemy still alive:

while enemy.health > 0:
    hero.attack(enemy)