Hi, don’t know how to do Leave it to Cleaver Backwoods Forest level. Plz help.
PS, how to display code in this form
? I can’t seem to do it with copying and pasting, espcially it does not work with indents.
Hi, don’t know how to do Leave it to Cleaver Backwoods Forest level. Plz help.
PS, how to display code in this form
? I can’t seem to do it with copying and pasting, espcially it does not work with indents.
in your def()
statement, did you define what target was?
e.g:
target = hero.findNearestEnemy()
Was that ALL of the code you posted? Could you post ALL of the code?
Yes that was all my code
What does target equal?
isn’t target the enemy?
It looks like you’re attacking before cleaving which is changing the timing of your attacks.
Anyone wanna explain why this:
// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called target
function cleaveWhenClose(target) {
if(hero.distanceTo(target) < 5) {
// Put your attack code here
// If cleave is ready, then cleave target
if (hero.isReady) {
hero.cleave(enemy);
}
// else, just attack target!
else {
hero.attack(enemy);
}
}
}
// This code is not part of the function.
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
// Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy);
}
}
Doesn’t work?
Please format your code using the </>
button when posting.
Your problem can be solved with the missing code cookies after def cleaveWhenClose(target). You also specified three attacks. One is unnecessary; the other two are proper.
If you can solve the riddle, Mr. Riddler would be happy to hop along your adventures!
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
hero.cleave(enemy)
# else, just attack target!
else:
hero.attack(enemy)
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)
?
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
hero.cleave(enemy)
# else, just attack target!
else:
hero.attack(enemy)
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)
This my code for leave it to the cleaver and it doesn’t work. The last two ogres aren’t getting attack. My family has tried it my brother and dad they both failed
it’s very difficult to see the problem because your code isn’t properly formatted for this forum, so I can’t see the structure. The proper use of the triple backticks when posting code can be found here:
https://discourse.codecombat.com/faq
One glaringly obvious problem is that your function starts out referring to target in the arguments but then you switch and start referring to enemy in the arguments. Consistency is important. Enemy is not defined in the function, just the code. The code can’t read definitions in the function and the function can’t read definitions in the code.
I don’t understand what you said and I learned by looking at my code when the last two ogres come out it tries to cleave them and it doesn’t use the else to attack instead. Please send more help. Sorry for all the trouble
Until you learn to properly post your code here - from the game - NOT by copying and pasting it from this board, help is going to be limited because we can’t see the structure of your code. Did you even look at the link I posted explaining how to do that? You must use the </> button. Please read and follow these directions when posting code. There are many people here who are willing and able to help, but you must apply a little effort to enable them to do so.
I finished the level sorry for getting back late
ive been stuck on this level for weeks and nothing has come so i need help
You’ve come to the right place for help, but unless you post your code we can’t see what’s wrong.
Please tell me how this does not work.
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
hero.cleave(target)
else:
hero.attack(target)
while True:
target = hero.findNearestEnemy()
if enemy:
cleaveWhenClose(target)
You’ve not defined enemy
. Try if target:
Nope the last 2 still live.