What do you not understand?
Andrei
What do you not understand?
Andrei
I cant understand anything because Iām dumb
Put this
Instead of this
Do you understand now?
Andrei
I think so I put 4 spaces down
its not working all my archers are going for any enemy not the strongest
Can you send me the code?
def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, "defend", defendPos);
# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
# Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
hero.command(archer, "attack", archerTarget)
elif nearest:
hero.command(archer, "attack", nearest)
archerTarget = None
while True:
# If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()
friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
archers = hero.findByType("archer")
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
for i, archer in enumerate(archers):
commandArcher(archer);
you still have not done what I told you!!!
Andrei
see I cant do anything right
I think I will let @Deadpool198 try to explain you better what do I tried to tell you.
Andrei
sorry if im not listening to you im just confused on this level
Deadpool you there can you help me understand this level
hello anyone there im still stuck
We know! Just be pacient and @Deadpool198 will respond to you. Just stop the spamming!
Andrei
Hi Liam,
letās start from your original code.
The first problem is here:
You need code in between those lines. It should use a while or for loop. Something along the lines of:
Loop through enemies:
compare health of enemy with mostHealth
update mostHealth and bestTarget
If you need more help with that go back to earlier sarven desert while loop levels.
Next this section:
You havenāt defined archer yet. Only archers. Why not use the same code as you used above:
Youāre trying to achieve the same aim. You could replace āsoldierā and āsoldiersā with āarcherā and āarchersā.
You should also go back to previous mountain levels for clarification of for loops. A lot of people find them hard. If you want I can give and in depth explanation of for and while loops, but if you could just go back to previous levels that would be easier.
Think about what Iāve said above, and experiment/go back to previous levels, maybe research loops on the internet (there are loads of resources). And come back in 24 hours and tell me if youāve made any progress.
I hope this helps,
Danny
I cant do it im just not following my dreams
im still confused im sorry if im not getting it im autistic
Can you send us your recent code?
Andrei
its still the same as last time
Can you resend it please?
Andrei
def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, "defend", defendPos);
# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
# Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
hero.command(archer, "attack", archerTarget)
elif nearest:
hero.command(archer, "attack", nearest)
archerTarget = None
while True:
# If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()
friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
archers = hero.findByType("archer")
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archer
for i, archer in enumerate(archers):
commandArcher(archer);
Click the space bar 4 times before those lines.
Andrei