I decided to head on back to some old replayable levels for fun and gems. This instance is for Backwoods Brawl. For some reason this code does not work and my hero just stands there.
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
I don’t see anything wrong. Can anyone help? Thanks!
I’ve been having problems like this too. I see nothing wrong with this code. The enemy = hero.findNearestEnemy() could be too old and you have to do enemies. Or the level isn’t working properly for your advanced equipment/code.
1 Like
Ok…
I also decided to do some old levels, but the hero did nothing. I reviewed the code and saw that, thanks to my new gear, the code was “outdated”. Like @BobBobson412 was saying, you might need to update your code to fit you gear like I did
Hope this helps!
1 Like
@BobBobson412 @barboon3 I think I know what you’re talking about since I have Programmaticon V (which is probably overloading the system with things like Math.atan2(y, x)
)
1 Like
You need different more non outdated code.
For example the past code could be find.NearestEnemy
and the new code is find nearest enemies with a for loop.
1 Like
I think you may need ("attack")
1 Like
Try redefining enemy. The hero may be confused if it already killed it.
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
friends = hero.findFriends()
enemy = hero.findNearestEnemy() [or something like that, I'm no expert at Python]
for friend in friends:
hero.command(friend, "attack", enemy)
2 Likes
Thank you so much for all the advice! I managed to get up from 4 to 6!
1 Like