Difference between revisions of "DCS func searchObjects"

From DCS World Wiki - Hoggitworld.com
m (1 revision imported)
 
Line 63: Line 63:
 
    
 
    
 
   local ifFound = function(foundItem, val)
 
   local ifFound = function(foundItem, val)
     foundUnits[#foundUnits + 1] = foundItem:getName
+
     foundUnits[#foundUnits + 1] = foundItem:getName()
 
     return true
 
     return true
 
   end
 
   end

Revision as of 23:24, 2 June 2020

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:
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: