When | Mood | Music |
2012-04-15 17:30:00 | confused | Wombo Lombo – Angélique Kidjo |
I think the bug I’m currently trying to squash is in the ‘remove’ method called from battle(). I’ve traced it by putting single lines of code to display a number after each step. So far, the numbers appear in order.
The remove method works by finding the position (index) in the ArrayList of the creature to be removed, then removing the creature at that index. (You can’t do simply ‘remove this type of creature’. The remove step needs two parts so that you don’t try to remove something from a collection that’s currently being examined – that way lies crash city.)
I was puzzled because the index of the creature to be removed was constantly ‘1’, even though the first creature to be added was an ogre – and the remove code will only work if the creature to be removed is an enemy.
I’d forgotten that computing numbers start at ‘zero’. Bah!
Back to bug-squashing…