Two issues, neither are really “yours”…
- “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"
;; 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”
;; 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:
(.moveXY this (.x (.pos this)) (.y (.pos this)))
will move you to where you currently are.