Raised This Month: $ Target: $400
 0% 

activating ents


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
TiToTal
Member
Join Date: Feb 2006
Old 03-05-2006 , 10:35  
Reply With Quote #3

Quote:
Originally Posted by PM
find_ent* functions always only return the first entity found. You have to continue calling it, most likely in a loop, in order to find all matching entities.

From find_ent_by_tname's funcwiki entry, you can see that the function takes a "StartEntity" parameter. I guess that the searching will begin on the entities after this one. It says that startentity should be -1 if you want to search from the beginning. Also, you can see that the function returns 0 if nothing is found.

So, your code would most likely work this way:

find_ent_by_tname(-1,"door")
returned 0? yes -> stop; otherwise:
force_use(id, what it returned)
find_ent_by_tname(what it returned,"door")
returned 0? yes -> stop; otherwise:
...

It's wise to use a variable for this:
Code:
new entid = -1 while (entid = find_ent_by_tname(entid, "door"))    force_use(id, entid)

As you can see, we first set entid to -1; then, we enter the while loop. Here, the condition part ( the thing inside () ) is evaluated. It sets entid to the return value of find_ent_by_tname. The value of an assignment operation is the new value, so if this will be 0, the while loop will exit. If this is nonzero, we go to the force_use line. Then the condition is evaluated again, using the last returned entid as "StartEntity". etc. This could work!

I understood, but I think there is something missing.. I got a error when compiling: "warning 211: possibly unintended assignment"
this warning message is for the line:
Code:
while (entid = find_ent_by_tname(entid, "door"))

isn't it possible to do it with "if" instead of "while" ?
I don't know...
TiToTal is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode