Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Ive tried this the error is mainly coming from the for loop that updates/removes the battleObjects. Commented Apr 6, 2014 at 19:46
  • 1
    I guess you update method might be trying to do something that changes the objects list. Inside a for each, you cannot modify the objects collection. Commented Apr 6, 2014 at 19:55
  • the monster update is calling the createNewBattle method which is changing the game state and add the monster and player to the battle objects. Commented Apr 6, 2014 at 20:00
  • Right, and that's what you can't do using the for each... you cannot add new elements into objects or remove elements from it. You can create a secondary lists with the objects you want to add AFTER the for each. Check it here: stackoverflow.com/questions/993025/… Commented Apr 6, 2014 at 20:04
  • "How about building a Queue with the elements you want to iterate over; when you want to add elements, enqueue them at the end of the queue, and keep removing elements until the queue is empty. This is how a breadth-first search usually works." Im not quite sure what he's saying here. Commented Apr 6, 2014 at 20:07