I need help with summits Gate

The problem with your code, as you’ve probably found out, is the commanding.

Here, you’re using a for loop to single out a single soldier to command.
In the command Paladin function you’re doing the right thing: commanding a single paladin.
But in the archer and soldier you’re making another for loop, why? Why not command the single friend that you very cleverly made in the commandFriends function (‘archer’ and ‘soldier’.)
You can take this code and use it just for archer, you don’t need to loop through all your friends again, because you did that in the commandFriends function:

I hope this helps
Danny

I dont know where to put that in

Can someone tell me where that goes.

This section, and the section from your soldier commanding code, out of the for loop. Should stay where they are, but you need to get rid of the for loop and command the ‘archer’ and the ‘soldier’ rather than ‘friend’ from your for-loop.

Ok ill try that thank you

So your saying I should delete the for loop im sorry im really confused

So it should look like this?

def commandArcher(archer):
    tower = hero.findByType("tower") 
    enemy = hero.findNearestEnemy() 
    if enemy: 
        hero.command(archer, "attack", enemy)

def commandSoldier(soldier):
    friends = hero.findFriends()
    for friend in hero.findByType("soldier"):
        catapult = friend.findNearest(hero.findByType("catapult"))
        if catapult:
            hero.command(friend, "move", {'x': catapult.pos.x, 'y': catapult.pos.y})

It’s alright.

This section is what I’m talking about.
When you’re commanding troops, you can use a for loop straight away:

for friend in friends:
    hero.command(friend, 'dosomething', someone)

OR:

def doSomething(friend):
    hero.command(friend, 'dosomething', someone)
for friend in friends:
    doSomething(friend)

As you can see, in the second example you make a function to command ONE friend. Then you use a for loop and call the function for each INDIVIDUAL troop (sorry for the caps, I want to accent those words because they’re very important)
Your trying to mix these tactics.
The functions commandArcher and commandSoldiers should be commanding INDIVIDUAL soldiers and archers, then you can call them for each troop in the for loop in your commandTroops function.
Imagine commandArcher was a single command like hero.command(archer, ‘attack’, enemy), you’re only commanding one soldier to do something. You don’t need another for loop inside your commandArcher function you can use just something like:

enemy = hero.findNearestEnemy()
if enemy and someCondition == True:
    hero.command(archer, 'doSomething', enemy)

You don’t need another for loop

Ok, in response to your new reply- Yes, well done, the archer function is good. Now you can do the same with the soldier function.
Danny

Ok , thank you Danny i will do that.

1 Like

So like this? @Deadpool198

def commandSoldier(soldier):
    tower = hero.findByType("tower") 
    enemy = hero.findNearestEnemy() 
    if enemy: 
        hero.command(soldier, "attack", enemy)
    catapult = friend.findNearest(hero.findByType("catapult"))
    if catapult:
        hero.command(friend, "move", {'x': catapult.pos.x, 'y': catapult.pos.y})

[en_US.composer.my_buttons_text]

after i reach the inner gate everyone stops moving and I run out of time.

OK so I changed my code to this

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

def commandArcher(archer):
    tower = hero.findByType("tower") 
    enemy = hero.findNearestEnemy() 
    if enemy: 
        hero.command(archer, "attack", enemy)

def commandSoldier(soldier):
    friends = hero.findFriends()
    catapult = friend.findNearest(hero.findByType("catapult"))
    if catapult:
        hero.command(friend, "move", {'x': catapult.pos.x, 'y': catapult.pos.y})

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin, "cast" "heal", hero)
    elif enemy:
        hero.command(paladin, "attack", enemy)

def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        if friend.type == "archer":
            commandArcher(friend)
        if friend.type == "soldier":
            commandSoldier(friend)

while True:
    commandFriends()
    attack()

Is it working? I feel like at this point it’s kind of to do with your tactics because that code doesn’t seem to have any errors.
Danny
P.S. you may want to use flags.

it still doesnt work

In what way?
Is it still

or smth else?

i stop at the warlock

I dont even move now

maybe you should focus on the warlock and if there is a warlock attack it, else have everything in your code.