From 54b626cd2934aa01d12f6a26a2d30dc026bb06e3 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 28 Jul 2022 22:23:20 -0500 Subject: [example] adde note about dropping ghouls while iterating over them --- examples/09-ghoulspree.lisp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'examples/09-ghoulspree.lisp') 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)) -- cgit v1.2.3