Difference between revisions of "DCS func searchObjects"

From DCS World Wiki - Hoggitworld.com
 
(2 intermediate revisions by 2 users not shown)
Line 15: Line 15:
 
|desc= Searches a defined volume of 3d space for the specified objects within it and then can run function on each returned object.  
 
|desc= Searches a defined volume of 3d space for the specified objects within it and then can run function on each returned object.  
  
Object category is either a single enum or a table of enums that defines the types of objects that will be searched for
+
Object category is either a single enum or a table of enums that defines the types of objects that will be searched for.
  
Search volume is the defined 3d space that will be searched.
+
Search volume is the defined 3d space that will be searched. See pages for the correct format of each volume type:
 +
 
 +
{{listOfVolumes}}
  
 
Handler is the function that will be run on each object that is found.
 
Handler is the function that will be run on each object that is found.
Line 78: Line 80:
  
 
[[Category:Singleton Functions|searchObjects]]
 
[[Category:Singleton Functions|searchObjects]]
 +
[[Category:Game Patch 1.2.4|searchObjects]]

Latest revision as of 23:40, 21 April 2023

Scripting Root

Envrioment: Mission Scripting
Function: searchObjects Added with: 1.2.4
Member Of: world
Syntax: table world.searchObjects(table/enum Object.Category , volume searchVolume , ObjectSearchHandler Handler , any data)
Description: Searches a defined volume of 3d space for the specified objects within it and then can run function on each returned object.

Object category is either a single enum or a table of enums that defines the types of objects that will be searched for.

Search volume is the defined 3d space that will be searched. See pages for the correct format of each volume type:

Volumes: segment, box, sphere, pyramid

Handler is the function that will be run on each object that is found.

Any data is a variable that is passed to the handler function, it can be anything.


Return Value: table
Return Example: Object
Examples: The following example would populate the table "foundUnits" of any unit found within a sphere defined by the zone "town"
 local foundUnits = {}
 local sphere = trigger.misc.getZone('town')
 local volS = {
   id = world.VolumeType.SPHERE,
   params = {
     point = sphere.point,
     radius = sphere.radius
   }
 }
 
 local ifFound = function(foundItem, val)
    foundUnits[#foundUnits + 1] = foundItem:getName()
    return true
 end


 world.searchObjects(Object.Category.UNIT, volS, ifFound)
Related Functions: World Functions: addEventHandler, removeEventHandler, getPlayer, getAirbases, searchObjects, getMarkPanels, removeJunk
Notes: