loop:
enemy = self.distanceTo()
if enemy < 5:
self.cleave(enemy)
else:
self.attack(enemy)
You are kind of mixed up there.
enemy should be set to findNearestEnemy not distanceTo
enemy = self.findNearestEnemy()
then you need to store distance
distance = self.distanceTo(enemy)
then
if distance < 5:
but dont forget to check if enemy exists before getting the distance
i get unexpected token when i try and store distance
distance = self.distanceTo(enemy)
loop:
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if enemy:
pass
if distance < 5:
self.cleave(enemy)
else:
self.attack(enemy)
Try having distance = self.distanceTo(enemy)
after if enemy:
. Right now it doesn’t know if there’s an enemy or not to find a distance to, so how can it find a distance to a possible enemy that’s possibly not there?
Im still confused, i moved it under if enemy and still didnt fix the problem…
loop:
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy)
if enemy:
pass
if distance < 5:
self.cleave(enemy)
else:
self.attack(enemy)
The levels before this one were pretty easy,but i hit a brick wall here…why no real help…i used what has been givin so far and has not helped…i want to keep learning but not sure what else to do
You can not call any function that passes in enemy without having it inside an if enemy block. thats your problem.
like this? my dude just stands there
loop:
enemy = self.findNearestEnemy()
if enemy:
pass
distance = self.distanceTo()
if distance < 5:
self.attack(enemy)
else:
self.cleave(enemy)
The problem is your line pass
If you enter your code using the code tag it makes it easier for us to see your indentation. I’ve updated your code with the tag to help see what is happening. (If you edit the post you can see how I did it.)
You need to indent the line
if distance < 5:
and the others after it. You are only checking distance if there is an enemy.
Currently your code says if there is an enemy calculate the distance. Regardless of the previous answer, if the distance is under 5 attack the enemy, otherwise cleave.
To put it in another context, it is like you have written out interview questions:
First, ask if there are cookies.
Then ask if the cookies are chocolate chip.
If they are not chocolate chip, then they must be oatmeal raisin.
imagine you have this conversation with your mom:
You: Do we have any cookies?
Mom: No
You: Are they chocolate chip cookies?
Mom: ???
If the first answer is no, you shouldn’t do anything. If the first answer is yes, then you will want to check the cookie type.
Hope that made sense.
hmm yeah maybe i need to go watch more tutorials on youtube…thanks for trying to help me tho
loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance < 5:
self.cleave(enemy)
else:
self.attack(enemy)
Any help??? I cleave just fine, but Anya just stands there while munchkin ogres spill her blood all over the meadow. I am using Java Script.
loop {
var enemy = this.findNearestEnemy();
if(enemy) {
var distance = this.distanceTo(enemy);
if (distance < 5)
if (this.isReady("cleave"))
this.cleave();
}
else {
this.attack(enemy);
}
}
you are forgetting a { after your distance check
you forgot to use { } in your if commands
well in this round you’ll need extreme amount of health i think? ( i have Tharin with 491HP and ended up to 61HP) so instead of attacking in my else i just shielded til my cleave is ready to use.or maybe you can just run around? i don’t know. but hey i survived the round
loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance < 5:
self.cleave(enemy)
else:
self.attack(enemy)
She attacks the first group fine, but the next group kills her.
Help please
Indentations, they will save your life!
You want your code too look like this:
loop:
# <- Note the four spaces
enemy = self.findNearestEnemy()
if enemy:
#kill him just like above (again with 4 more spaces, 8 total)
With indentation you tell python what is inside and what is outside of a loop/if/…
Hi J_F,
Thank you. When copying and pasting the 1st two lines it removed the indent (4 spaces)
Here is the screenshot. While she’s been hacked to death it stays highlighted on line 6.
Below is the error i get if I try to indent line 3.
I found out what it was. Her armor wasn’t strong enough to handle the battle. I purchased new armor and she was fine.
I tried to shield her initially, but that didn’t work. Thanks for the help!!