DCS func searchObjects

From DCS World Wiki - Hoggitworld.com
Revision as of 23:40, 21 April 2023 by Grimes (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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: