loop:
enemy = self.findNearestEnemy()
if enemy:
distance = self.distanceTo(enemy)
if distance < 5 and self.isReady(âcleaveâ):
self.cleave(enemy)
else:
self.attack(enemy)
This code worked best for me. I canât figure out how to indent itâŚ
If there is an enemy⌠they are less than 5 from you⌠and you are ready to cleave⌠do so
Or else just attack the enemy. Each time your hero attacks the code will loop and check if the cleave is ready again. I hope that helps.
Thank You for this JS answer. And donât say your a beginner, more like a novice because I am a beginner and could not figure this one out :). I think the problem is that this is a âbrick wallâ in ratio to the other levels leading up to this one. The distanceTo mixed with the already known isReady can be too much at once. It would be nice to have a simpler distanceTo test and/or more clarification that the isReady(cleave) has to be used again also(!).
Thanks again for this post. at least I know something works.
Hi Guys, i have another problem:
Syntax error on line 1, column 1: unexpected âdâ (\u0064)
1 : plan = () ->
^ : ^
2 :
3 : loop:
4 : enemy = self.findNearestEnemy()
loop:
enemys = @findNearestEnemy()
if enemys
if @distanceTo(enemys) < 15
if @isReady "cleave"
@cleave enemys
else
@attack enemys
I also think that this level is broken with clojure.
Here is my code:
(dotimes [n 1000]
(def enemy (.findNearestEnemy this))
(if enemy
(do
;; Find the distance to the enemy with distanceTo.
(def distance (.distanceTo this enemy))
;; If the distance is less than 5 meters...
(if (< distance 5)
;; ... if "cleave" is ready, cleave!
(if (.isReady this "cleave")
(.cleave this enemy)
;; ... else, just attack.
(.attack this enemy)
)
)
)
)
)
I really think that this should work but my character just stands there.
âdoâ is broken, so we have to use â(whenâ to get multi-line clausesâŚ
;; if we need both the "true" and "false" clauses then we use "when true" instead of "do"
(if enemy
(when true
;; multi-line clause
)
(single line clause) ;; or "(when true" again for another multiline clause
or in your case, since you have no else-clause use âwhenâ instead of âif doâ
(when enemy
;; Find the ........
coco-closure has no fancy protected âloopâ command like has been added to the other languages. So âdoTimes [n infinity]â runs without breaks and is over before the mobs even get on the screenâŚ
To slow it down you have to perform some action every time around.
In this case the simpliest way is to add a moveXY as the last command of the doTimes
(doTimes [n 1000]
;; all your code here
(.moveXY this 39 32)
)
â39 32â is your heroâs start position, this causes you to move to the spot you are already at (unless you moved to âattackâ), stopping the code from racing off into infinity (and beyond).
Less simply, but slightly better would be to add the moveXY to every clause that doesnât contain an action (in this case that would be as the false-clause of every if that only has a true-clause⌠(the simple way always moveXYs even if it is not needed since another action (cleave/attack/etc) was performed.)
or for later levels, where you want to move away from your start spot:
As you can read in the FAQ, you can format your code correctly in posts by placing three backticks (`) before and after your code. Or, you can highlight it, then click the â</>â button.
You canât cleave every enemy because the âcleaveâ command has a specific cooldown of ten seconds. Instead of attacking if the distance is more than five meters, try checking to see whether you are ready to cleave; if you arenât, then attack, as it says in the comments in the code when the level first starts:
# Find the distance to the enemy with distanceTo.
# If the distance is less than 5 meters...
# ... if "cleave" is ready, cleave!
# ... else, just attack.
Wow, I have really convoluted code for this particular level.
I havenât looked at it in a long time.
I have a habit with my cleaves of making a variable storing how many enemies are within 5m and not launching my cleave if it is less than 3 or 4.
I did not do that on this level.
I also avoided declaring variables it looks like.