thank you .
I got it
thank you .
I got it
That is the code
[redacted]
I have also an error with this level.
The method āfindNearestEnemyā doesnāt show up and also the object enemy is null. Iām using JavaScript. My hero wears the wooden glasses, but in the lower right these methods are not displayed, so unusable.
You might have a better item than the early ones that provide findNearestEnemy.
in which case youāll need to do something like this.
self.findNearest(self.findEnemies())
as for the null enemy object, yes it will be null if there is not enemy at that moment. be sure to safeguard against this by putting all code that accesses the enemy object inside an
if enemy:
Been at if for some time and I canāt seem to figure it out.
var enemy = this.findNearestEnemy();
var distance = this.distanceTo(enemy);
loop {
if (distance < 10) {
this.cleave(enemy);
}
else {
this.attack(āChestā);
}
}
The thing is that my Hero wont stop attacking the āChestā even if the distance is < 10.
any tips for this problem.
I dont know why but my āelseā code wont work.
@LITE You need to find the enemy and calculate the distance within the loop. Having it outside the loop means itās only done once at the start, so your character will never find the enemy when your code is looping.
oooh got it. thanks!
loop: # Check the distance to the nearest enemy. # If it comes closer than 10 meters, cleave it! # Else, attack the "Chest" by name. if self.distanceTo(self.findNearestEnemy()):10 self.cleave(self.findNearestEnemy()) self.attack("Chest")
Merged Doublepost
this is my code can anyone help me with this please???
Did you get this in the end? If posting code itās best to format your code so we can see what is actually there (see the FAQ). Iām guessing this is Python, and assuming your indentation is ok (canāt really see from whats there), you might want to check the comparison used in your if - should be a < I think
thanks I got it now thanks for the help
On this topic . . .
The help video says to add .pos when you declare distanceto because āwe used it in the previous levelā. Um, no we DIDNāT. I had never seen it before now, and that isnāt in the code examples.
Iām wondering what happened there . . .
I believe I am using the exact code from the help video and yet it says the last line is not a function.
loop:
enemy = self.findNearestEnemy()
enemyDistance = self.distanceTo(enemy)
if self.isReady(ācleaveā):
if enemyDistance< 10:
self.cleave(enemy)
else:
self.attack(āChestā)
else:
self.attack(āChestā)
OK, I HAD TO SWITCH TO THE LONG SWORD AGAIN. i KEEP FORGETTING i NEED THAT TO CLEAVE. ON MANY LEVELS I HAVE HAD DIFFERENT KINDS OF CODE ERRORS WHICH I HAVE FOUND IN THE END TO BE A RESULT OF NOT HAVING THE RIGHT SWORD, BOOTS OR HERO.
Please do not post correct code! It is not allowed according to the Discourse FAQ @Conor_Extreme can you edit it out?
Here is what i have and nothing worksā¦
while True:
enemy = self.findNearestEnemy()
distance = hero.distanceTo(enemy)
hero.say(10)
enemy = hero.findNearestEnemy
if enemy < 10:
ready = hero.isReady("cleave")
hero.cleave(enemy)
else:
hero.attack("Chest")
hero.attack("Chest")
I recommend you press the āRestartā button at the top right corner of the screen and read the instructions carefully.