Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "find"

From Quake Wiki

(Created page with "====Syntax:==== <code>entity find(entity start, .string fld, string match)</code> Returns an entity who's entity variable matches <code>match</code> by searching through the ...")
 
Line 1: Line 1:
====Syntax:====
+
''entity'' '''find'''(''entity'' start, ''.string'' fieldName, ''string'' fieldValue)
<code>entity find(entity start, .string fld, string match)</code>
 
  
Returns an entity who's entity variable matches <code>match</code> by searching through the edict list starting from <code>start</code>.
+
== Usage ==
====Parameters:====
+
Searches through the entity list, finding the first entity whose field name has the passed field value. Can be used to iterate through every entity in the map to find specific ones e.g. an entity's targets when it activates.
:<code>start</code> - The entity to start searching from. Use <code>world</code> to start from the top of the list.
 
:<code>fld</code> - The field to check for matches.  Eg: .targetname
 
:<code>match</code> - The values to check for.
 
====Returns:====
 
:Returns an entity that matches the criteria
 
  
 +
=== Parameters ===
 +
*''start''
 +
:The entity to start from in the list, exclusive. Passing '''world''' will start from the very first entity.
 +
*''fieldName''
 +
:The name of the string field on the entity to check. This is a symbol e.g. if you wanted to check an entity's '''targetname''' field, you would pass <code>targetname</code>.
 +
*''fieldValue''
 +
:The value that the entity's field must be set to in order to be considered a match.
 +
 +
=== Return ===
 +
The first entity found starting after ''start'' whose field has the passed value.
 +
 +
== Example ==
 +
// This finds every target the entity has and sets their health to 200
 +
entity it = find(world, targetname, self.target);
 +
while (it)
 +
{
 +
    it.health = 200;
 +
    it = find(it, targetname, self.target);
 +
}
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Revision as of 14:31, 31 July 2023

entity find(entity start, .string fieldName, string fieldValue)

Usage

Searches through the entity list, finding the first entity whose field name has the passed field value. Can be used to iterate through every entity in the map to find specific ones e.g. an entity's targets when it activates.

Parameters

  • start
The entity to start from in the list, exclusive. Passing world will start from the very first entity.
  • fieldName
The name of the string field on the entity to check. This is a symbol e.g. if you wanted to check an entity's targetname field, you would pass targetname.
  • fieldValue
The value that the entity's field must be set to in order to be considered a match.

Return

The first entity found starting after start whose field has the passed value.

Example

// This finds every target the entity has and sets their health to 200
entity it = find(world, targetname, self.target);
while (it)
{
    it.health = 200;
    it = find(it, targetname, self.target);
}