Bigdog
September 20, 2022, 3:18pm
1
Hello,
This is my first time posting and I am stuck on a level. This is my code: I don’t know what the problem is can someone please help me.
friends = self.findFriends()
for i in range(len(friends)):
friend = friends[i]
enemy = friend.findNearest(friend.findEnemies())
if enemy:
if friend.health > friend.maxHealth/1.5:
self.command(friend, “attack”, enemy)
else:
self.command(friend, “move”, {‘x’:friend.pos.x - 40, ‘y’:friend.pos.y})
else:
self.command(friend, “move”, {‘x’:friend.pos.x + 40, ‘y’:friend.pos.y})
ZAX155
September 20, 2022, 3:20pm
2
Hello and welcome to the discourse. Can you please tell us which level is and please format your code correctly using the </> button. Thanks. Here are a couple of examples.
hero.say("Hello World")
or
while True:
enemy = hero.findNearestEnemy()
hero.attack(enemy)
distance = distanceTo(enemy)
if distance < 5:
hero.cleave
else:
hero.attack(enemy)
Note: this is just a sample code
ZAX155
September 20, 2022, 4:17pm
3
Do you still need help? If so, please let me know
Also, It would help to know what level you are experiencing difficulty with.
Bigdog
September 22, 2022, 12:49pm
5
The level is called Hunting Party, hopefully I have formatted the code correctly, it says to use the code toolbar button but am not sure what that is.
‘’
friends = self.findFriends()
for i in range(len(friends)):
friend = friends[i]
enemy = friend.findNearest(friend.findEnemies())
if enemy:
if friend.health > friend.maxHealth/1.5:
self.command(friend, “attack”, enemy)
else:
self.command(friend, “move”, {‘x’:friend.pos.x - 40, ‘y’:friend.pos.y})
else:
self.command(friend, “move”, {‘x’:friend.pos.x + 40, ‘y’:friend.pos.y})
‘’
Aya
September 22, 2022, 4:56pm
6
:] you can also surround your code with three back ticks like this one `
as for your code
you have to put everything in a while-true loop (so that it doesnt only iterate once over your friends, rather every time the for-loop is done)
change the 40 to 10 when you are adding a number to the “x” in the commands to move
probably that works
1 Like
Bigdog
September 26, 2022, 4:40pm
7
Thank you for helping me I appreciate it.
1 Like