Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Help me out with Mixed Unit Tactics please

it says that defendPoints isn’t defined. here’s my code:

summonTypes = ["soldier", "soldier", "soldier", "soldier", "soldier", "archer", "archer", "archer"]

def summonTroops():
    hero.say("I should summon troops!")
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
    else:
        coin = hero.findNearestItem()
        hero.move(coin.pos)

def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        friendIndex = 0
        defendPoints = [{"x"39:, "y":43}, {"x":39, "y":38}, {"x":39, "y":33}, {"x":39, "y":28}, {"x":39, "y":23}]
        defendPos = defendPoints[i % len(defendPoints)]
        hero.command(friend, "defend", defendPos)
        friendIndex += 1

while True:
    summonTroops()
    commandTroops()

Try to put this on line 2.

1 Like

Do you need any more assistance at this level?

1 Like

yes. it says this when i try to run it:
unexpected tokenexpected T_RBRACE but found T_NUMBER while parsing atom

Can you send me the code that you have?

1 Like

Sorry. I was looking in the previous level.
Just try to put this on line 2 instead of putting it in the for loop:

And delete those two:

Does it work now?

1 Like

the one on line two is said to have an unexpected token:
unexpected tokenexpected T_RBRACE but found T_NUMBER while parsing atom:

and here is my code:

summonTypes = ["soldier", "soldier", "soldier", "soldier", "archer", "archer", "archer", "archer"]
defendPoints = [{"x"39:, "y":43}, {"x":39, "y":38}, {"x":39, "y":33}, {"x":39, "y":28}]
# unexpected tokenexpected T_RBRACE but found T_NUMBER while parsing atom: 
def summonTroops():
    hero.say("I should summon troops!")
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
    else:
        coin = hero.findNearestItem()
        hero.move(coin.pos)

def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        defendPos = defendPoints[i % len(defendPoints)]
        hero.command(friend, "defend", defendPos)

while True:
    summonTroops()
    commandTroops()

On what line do you get the error?

1 Like

line two. (20 chars)

1 Like

Here is the issue. Put this instead:

"x":39

Does it work now? :face_with_raised_eyebrow:

yes but for some reason i can’t get the bonus even if my hero survives for 60 seconds :thinking:

i got it by submitting :rofl:

thanks @AnSeDra (20 chars)

No problem! And congratulations for completing the level and the bonus! :partying_face:

1 Like