swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] Objects on multiple lists


From: Darold Higa
Subject: Re: [Swarm-Support] Objects on multiple lists
Date: Mon, 17 Feb 2003 19:30:27 -0800

On Monday 17 February 2003 04:13 pm, you wrote:

Thanks!  This helps a lot.

> To make a simple answer short, Yes. temporaryAgentList, the way you
> programmed it, is just another name for the list inside your
> terrainObject. Instead, you need to make a new list and put the same
> objects on both (if that's what you want).

OK, I guess I should have read the manual on collections more clearly.  That 
makes a lot of sense and that explains why it removed all objects from the 
original list.

> So any object can be on as many lists as you want, each list is just a
> list of pointers to that object. Just be careful when you go to drop an
> object that you go through all the lists that it is on and remove it
> from those lists. (Or you can maintain one master list of objects that
> still exists, and continually empty and re-build your temporary lists-
> may not be the fastest code but often it's the fastest way to get your
> job done.)

Yes, I learned this one the hard way.  I have tried to be very careful with 
agent deaths.  Since my poor agents can die several ways, I have to be extra 
careful about removing them from every list.

> > 2A.  If a list is made of objects through addLast, what effect will
> > removing and or dropping items from this list have on any other lists?

> *Removing* an object from a list does not affect the other lists. If you
> *drop* an  object that is still on a list somewhere, you are asking for
> trouble. If your code tries to do anything with all the objects on a
> list and some of those objects have been dropped (e.g., by using
> deleteAll on another collection containing the object) your code will
> crash. Best to always remove an object from all the lists it is on, then
> delete it.

That is what I remember hearing.

> > I have targetAgentList as a subset of localAgentList.  If I eventually
> > remove all from the targetAgentList, will it affect localAgentList?

> Don't think so...not sure what you mean by 'subset'. But again, removing
> something from one list has no effect on another list.

Hmm, I guess that wasn't very clear.  I guess there is no abstract way to 
explain what I'm doing here.  In my simulation sometimes agents commit 
violent acts against other agents in their local area. The targetAgentList is 
made of agents on the localAgentList that are valid targets for a given type 
of attack for a given agent, since my agents attack others based on a variety 
of factors, including their identity.  Because the agent might not attack 
some of the agents on localAgentList, the targetAgentList is a 'subset' of 
the localAgentList, only including agents that are valid targets.

> Some of this is described in the reference manual - look in the section
> on the Collections library and look at "Collection"- lists etc. are
> subclasses of Collection.

I was reading it but somehow I managed to make myself more confused.  I think 
I am clear now.  Thanks!

> Steve

Darold


reply via email to

[Prev in Thread] Current Thread [Next in Thread]