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

Please help summit's gate!

while True:
enemy = hero.findNearestEnemy()
friend = hero.findNearest(hero.findFriends())
flag = hero.findFlag(“green”)
if flag:
hero.pickUpFlag(flag)
elif enemy:
distance = hero.distanceTo(enemy)
if friend:
hero.command(friend, “attack”, enemy)
if enemy:
hero.attack(enemy)
if friend:
hero.command(friend, “defend”, hero.pos)
if hero.gold >= hero.costOf(“soldier”):
hero.summon(“soldier”)

Hi @JSW. Welcome to the codecombat discourse.
I think the only advice I can really give is to make your code a lot more complicated. It’s definitely a good idea to use flags, but I would also use functions to command different troops separately, so you can command paladins to heal for example.
My code was nearly 100 lines when I was done, so I think you should try and use every possible resource you can.
I would also recommend using a wizard/ranger as you are a subscriber. Nalfar Cryptor would work well. You could use him and the Undead Tome V, I find that a very good combo.
I hope this helps,
Danny
P.S. could you also post a screenshot of all of your available equipment.

1 Like

Also, for future reference, could you post your code formatted (instructions here: Link) and put it in the Level Help category. (I did it this time.)
Thanks
P.S. I like your profile picture :wink:, you have good tastes.

1 Like

Hmm… But my Nalfar Cryptor is very weak… because I don’t have good equip for wizards…

Hmm… I need to buy anything?

Oh, okay, yeah I think it would be best if you used the warrior, or maybe the range but not the wizard.

1 Like

Now OK?

What’s wrong with this code?

while True:
enemy = hero.findNearestEnemy()
friend = hero.findNearest(hero.findFriends())
flag= hero.findFlag(“green”)
catapult = enemy.type == “catapult”
pet.chase(enemy)
if flag:
hero.pickUpFlag(flag)
elif enemy:
distance = hero.distanceTo(enemy)
if hero.health < 800:
hero.cast(“drain-life”, enemy)
if friend:
hero.command(friend, “attack”, enemy)
if enemy:
hero.attack(enemy)
if enemy.type == catapult[0]:
hero.devour(catapult)
if enemy.type == catapult[1]:
hero.devour(catapult)
if friend:
hero.command(friend, “defend”, hero.pos)
if hero.gold >= hero.costOf(“soldier”):
hero.summon(“soldier”)
if “paladin”.health < 500:
hero.command(“paladin”, “heal”)

Could you post your code formatted. Instructions: How to Post Your Code With Radiant, Harmonious Formatting. And do you have an error? Or is it just not working to complete the level.
When you post your code could you give as much info. as possible so I don’t have to spend quite a lot of time finding out what you already know.
Thanks
Danny

Reviewing each line out of context, these few lines don’t quite look correct. It looks like you are trying to put all of the catapults into a list that you check against later. Your first line is an object variable and will only accept one object so you can’t use an index later on. Currently your catapult variable will only show True or False (is the enemy type a catapult?)

catapult = enemy.type == “catapult” # can remove this line since you are checking type later
hero.devour(catapult) # won't work since catapult is a boolean variable not an object variable, change to enemy

if enemy.type == catapult[0]:
This section isn’t comparing correctly. Check to see if the enemy is a catapult type like above. Using the same name for a type and variable can make it difficult to discern which one you are trying to reference.

Extra note, the Devour has a cooldown of 5 seconds so you want to check to see if you are able to use it before commanding the devour otherwise your hero won’t do anything else until the 5 seconds is up, same check with the Drain-Life spell.