We don’t give full solutions as a forum policy. This is because the concepts you are supposed to learn in this level will be necessary in future levels, so if you don’t understand it properly you will likely get stuck again soon and it will be harder to help you then.
Bryukh did a pretty good job describing what you have to do, but I’ll write it in a different way so you can have another go at it.
This level is supposed to teach you how Boolean values work (a Boolean is a value that can be true
or false
), and to use them inside a condition.
The shouldAttack
function returns a Boolean (true or false) indicating whether you should attack the target or not. So what you have to do is to store the result of this function inside a variable:
local doAttack = hero:shouldAttack(target)
Here, you are passing the nearest enemy to the shouldAttack
function and it will return whether you should attack it or not, then this result is stored in the doAttack
variable.
At this point, the doAttack
variable contains a value that is either true
or false
. Now you can do a conditional check (if doAttack then
) to only perform an action when doAttack
is true
. This part is already correct in your code. Inside the conditional block, you are supposed to attack
the target—I believe you should know how to do this by now.
In the future, please be specific with what you didn’t understand, so that we may be able to help you. Human communication is the most important programmer skill!