Josh Matthews wrote:
Two points, one, I don't see how my second method will skip over
entities.  It keeps searching until it doesn't find one class, then
goes on to the next.

Let's say you only have 4 entities in the world, in this order...

worldspawn ---> light_spot ---> light_environment ---> light

Your switch code goes through 3 states (case 0, 1, or 2).  In each
state, it increments the pointer to the next entity in the linked list
that matches what you are searching for in that state (i.e. in state 0,
it searches for a "light" entity and returns the pointer to it.

So, if you with the entity pointer as NULL, and search for "light", the
engine will start at "worldspawn", won't find a match in classname, will
bump to the next entity (light_spot), won't find a match in classname,
will bump to the next, and so on until the engine finds the "light"
entity at the end.  The engine will return the pointer to this entity.

Now your code bumps to state=1, and continues from the "light" entity
pointer looking for "light_spot".  Lo and behold, no "light_spot"
entities are found, because the engine is already at the end of the list.

Then you bump to state=2 and the same thing happens.  No
"light_environment" entities because the entity pointer is already at
the end of the list.

You need to search the linked list separately for each class of entity.

 The other, I don't understand what you mean
about "m_iPowerzone will only be meaningful in the context of the
class this code is being called in."

What I mean is that if "m_iPowerzone" is a member variable of light_spot, and this code is called from within a light_spot class, the member variable m_iPowerzone will only contain whatever string you have assigned to it in that specific class instance.

You code appears to want to do this...

for each entity...
   check if the entity contains a key value called "m_iPowerzone" AND
   check if the entity with the "m_iPowerzone" key contains a string
that is equal to the string pointed to by the m_iPowerzone member
variable of that entity class instance. (i.e. search through all
entities to find an entity that has a key value that is equal to
whatever value has been assigned to that particular entity).

No such comparison will happen.  You are passing in a static char
pointer (whatever m_iPowerzone happens to point to) when the
UTIL_FindEntityByString() is called.  This comparision string will not
change as each entity in the linked list is evaluated (and perhaps that
was your intent, to compare each entity in the linked list to a specific
non-changing string).

I've added an m_iPowerzone variable to the light base class in the
fgd, and I've also added a handler in the KeyValues function for
CLight.  In addition, I have made a trigger_powerzone entity which has
its own m_iPowerzone variable (and respective KeyValue handler), and
in its Use function it finds all lights with the same powerzone
(UTIL_FindEntityByString(pEnt,"m_iPowerzone",m_iPowerzone)) and
switches them off.  Shouldn't this find the light entities, seeing as
the trigger_powerzone class has a powerzone to search for, and all the
lights have powerzone variables as well?

Yes, it wasn't clear that m_iPowerzone was actually coming from some other entity (in this case, trigger_powerzone). If you call the UTIL_FindEntityByString() from within the "trigger_powerzone" class and pass in the value of m_iPowerzone contained within this trigger_powerzone class, it will find all other entities with a "m_iPowerzone" key that has a value that matches the value of m_iPowerzone contained in the "trigger_powerzone" class.

In this case, it does what you want (compares the key/value of all
entities to a constant string from the trigger_powerzone class instance).

--
Jeffrey "botman" Broome

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



Reply via email to