Level: Leave It To Cleaver Help (solved)



so I can’t seem to beat this level when most others seemed to be relatively easy. I simply get an error every time that says “function cleaveWhenClose() not defined”. The point of the level is to define a function and I feel as if I’ve put in all the code it requires as well as tried to play with it for hours to no avail.

`-- This shows how to define a function called cleaveWhenClose
– The function defines a parameter called target

function cleaveWhenClose(target)

if hero:distanceTo(target) < 5 then
     -- Put your attack code here
     -- If cleave is ready, then cleave target
    if hero:isReady("cleave") then
     -- else, just attack target!

– This code is not part of the function.
while true do
local enemy = hero:findNearestEnemy()
if enemy then
– Note that inside cleaveWhenClose, we refer to the enemy as target.
This is my code. Idk if it formatted correctly.


You need to scope your functions like you do variables.


local function cleaveWhenClose(target)


Thanks! This has been an issue for me for variables and I had thought about it for the function but just in a weird, roundabout way. This solved it for me


What would this look like in java script?


If you need help with the level, copy paste your code and surround it top and bottom with 3 backticks ( ` )

if(hero.distanceTo(target) < 5) {
        if(hero.distanceTo(enemy) < 5) {
        var ready = hero.isReady("cleave");
        hero.cleave(enemy); }                              
        else {

“I didn’t add the game page instructions.”


Did you define target or enemy in your code?


No, lol I Can’t believe I missed that, Thanks.


what deos it translate to in python?


i need help with the programe


I think there is a laguage trasnlator