Difference between revisions of "DCS func searchObjects"

From DCS World Wiki - Hoggitworld.com
m
Line 78: Line 78:
  
 
[[Category:Singleton Functions|searchObjects]]
 
[[Category:Singleton Functions|searchObjects]]
 +
[[Category:Game Patch 1.2.4|searchObjects]]

Revision as of 07:13, 17 March 2022

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.

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: