while True:
weakest = None
leastHealth = 99999
enemyIndex = 0
enemies = hero.findEnemies()
while enemyIndex < len(enemies):
if (enemies[enemyIndex].health < leastHealth):
weakest = enemies[enemyIndex]
leastHealth = enemies[enemyIndex].health
enemyIndex += 1
if weakest:
hero.attack(weakest)
pass
pls help me!
My hero dies right before defeating the final enemy. I have 3625 health with Tharin. So I don’t think that that is the problem. But if it is pls let me know.
It says to attack the furthest, not the weakest enemy.
My problem is with mad maxer strikes back. Am soooo sorry about that mistake of mine.
I think it is a solution since this code works for you and you passed the level.
Oof, I’ll go look at it, since I haven’t completed it yet…
Oh wait, nevermind, I did complete it… anyway… your mistake is that you put
if weakest:
hero.attack(weakest)
in the while loop.
And, also, please remove the parentheses in (enemies[enemyIndex].health < leastHealth)
they aren’t needed and sometimes might cause an error.
Also, just a tip: use for loops to iterate through lists, like this:
Python:
List = randomList() # this function doesn't actually exist, I'm just using it for an example.
for item in List:
doSomething() # this function doesn't actually exist, I'm just using it for an example.
# and if you also want the index of the item for something
for i in range(len(List)):
item = List[i]
doSomething() # this function doesn't actually exist, I'm just using it for an example.
# and if you don't want to use a list
howManyTimesToRepeat = giveMeARandomIntegerFrom(1, "to", 5); # this function doesn't actually exist, I'm just using it for an example.
for i in range(howManyTimesToRepeat):
doSomething();
Javascript:
let List = randomList(); # this function doesn't actually exist, I'm just using it for an example. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
for (let item of list) {
doSomething(); # this function doesn't actually exist, I'm just using it for an example. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
}
# and if you also want the index of the item for something. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
for (let i in List) {
let item = List[i];
doSomething(); # this function doesn't actually exist, I'm just using it for an example. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
}
# and if you don't want to use a list. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
let howManyTimesToRepeat = giveMeARandomIntegerFrom(1, "to", 5); # this function doesn't actually exist, I'm just using it for an example. Also, I'm using Python comments since coco always thinks that people write in Python in these snippets.
for (let i = 0; i < howManyTimesToRepeat; i++) {
doSomething();
}
Ah, but the thing is, for loops aren’t covered in the desert and I doubt @hellodaddy will have access to them through Programmaticon IV.
You can use them no matter what Programmaticon you have. You could have Programmaticon I and you would still be able to use them. It’s a built-in javascript function, same as arrays and variables.
yes there is an error where with progmat 1 u can use if or else + for+while but @moonwatcher348 please dont assume everyone understands everything like javascript because some people like me use python
I’m not assuming everyone understands javascript, I’m just saying it in the first way that comes to my mind.
but still please try explaining in both python and javascropt
The problem is that my hero dies right before the final enemy. The code works fine. My hero has 3,625 health with THARIN and still die early. what should I do?
It takes a while to process it, and I don’t like Python.
Tharin is a non-premium hero, so why are you emphasizing his name? Also, it does not work. I tested it on mine and changed it to putting the if weakest
outside of the while loop with me having only ~600 health and still won.
1 Like
And, no offense, but I’m in Kelvintaph and have programmed quite a few complicated things, so please do not say that your code is fine when I say its not. (unless you test it and it works the same)
Thank you so much! And I am sorry for saying that my code works. It’s just that he would attack the enemies but he would die quickly. But thanks a lot. Really helpful.
1 Like
why do my topics have the most veiws out of all the new ones for this week?
1 Like
I feel so famous. even though there is only 80 people.
1 Like