aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-07-28 22:23:20 -0500
committerColin Okay <okay@toyful.space>2022-07-28 22:23:20 -0500
commit54b626cd2934aa01d12f6a26a2d30dc026bb06e3 (patch)
tree1d1eb1e188e26ac91927bf4e8074dd0b2164ca5d
parent36c004c17f6d7380ab10e3c88983788d85434de4 (diff)
[example] adde note about dropping ghouls while iterating over them
-rw-r--r--examples/09-ghoulspree.lisp9
1 files changed, 8 insertions, 1 deletions
diff --git a/examples/09-ghoulspree.lisp b/examples/09-ghoulspree.lisp
index 03552f0..a11e6a6 100644
--- a/examples/09-ghoulspree.lisp
+++ b/examples/09-ghoulspree.lisp
@@ -102,7 +102,14 @@ on which boundary VAL is outside of."
when gravity
do (apply-gravity-to ghoul accelleration)
when (out-of-bounds-p ghoul)
- do (ww:drop-unit ghoul)))))
+ ;; note, it is generally a BadIdeaâ„¢ to delete
+ ;; something from an array that you are iterating
+ ;; over. It only works as expected here b/c of
+ ;; implicit knowledge about the imlementation of the
+ ;; scene container. A safer way in most cases would be
+ ;; to `collect ghoul into drop-list` and then deleted
+ ;; all the collected ghouls in a `finally` clause.
+ do (ww:drop-unit ghoul)))))
(defun random-sign ()
(if (zerop (random 2)) -1 1))