This is not the bug you’re looking for

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…

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.