I need help with summits Gate

ok what should i fix

can anyone help or no

what do you think i should do @abc

You should summon your soldiers, archers, and paladins like you did, but I think maybe the problem is your while true loop:

while True: commandFriends() 
attack()

This is because even though you used the same for loop in the function, you should use it again like this:

While True:
friends = hero.findFriends()
    for friend in friends:
        commandFriends() 
    attack()

Also what character are you using. Certain characters could help in this level, like rangers

ok thank you @abc i will try that and im using Alejandro

My code isnt running before it even loaded the level it said i had in infinite loop detected

my people dont even m ove what the heck is wrong :rage: :rage: :rage: :rage: :rage: :rage:

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]