I have a big problem these days.
I have one global array such as Fruit, which has all the fruits. for example:
var Fruit = [Apple, Peach, Pear, ...]
and there are one class "PLAYER", which can change this array at any time.
PLAYER.eat(Apple) # will remove the Apple from Fruit array
Then, I have ten thousand Farmers that inherits another class called "NPC". the NPC iterate the Fruit array and call the logic about each fruit, such as :
for eachfruit in Fruit:
then there will be big problem: some fruit may be eaten in the for loop, so each_fruit will be null can cause an error
and i find some book that said the for lool will lock the global Fruit Array? is this true? But i find that PLAYER can always eat the fruit, so i really doubt it .
Anyone know the answer will help me a lot, thanks!