Jump to content

Recommended Posts

Posted

I'm getting back into adding scripts into missions, but I've run into a problem. What I specifically want to do is enhance AWACS functionality, and to do that I need access to what they've detected.

 

 

I've created a test mission with a simple script, but I can't get it to work and I'm not sure what the problem is. I keep getting a nil error when I try to get information from the list of detected targets.

 

 

This is the script:

 

 

cmnd = Unit.getByName('E3')

logi = Unit.getController(cmnd)

list = logi:getDetectedTargets(RADAR)

obj = list[1]

if obj ~= nil then

   tgt = obj:getTypeName(Object)

end

I've also attached the mission. From what I can tell, list should be a table of Objects. It's not nil because it passes the if. list[0] and list[2] don't pass, so I'm sure list[1] is a valid index. It doesn't seem to be an Object though. Does anyone see what's wrong?

 

 

I also have a second trigger in the mission just to make sure I understand syntax and function. It performs getTypeName on the player craft and runs successfully.

Detect.miz

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Posted (edited)

Maybe instead of RADAR you have to use the enum like this:

 

Conroller.Detection.RADAR

Also getDetectedTargets does not return a table of objects. Instead it returns a table of tables that contain informations about the detected objects. More precisely you can look up the structure of the return value it in the documentation: https://wiki.hoggitworld.com/view/DCS_func_getDetectedTargets

Last but not least you have used getTypeName in a wrong way. You should be very careful, before you start testing your scripts. Probably you should refresh your Lua skills a bit. :)

 

So instead of your code I would try

 

cmnd = Unit.getByName('E3')
logi = Unit.getController(cmnd)
list = logi:getDetectedTargets(Conroller.Detection.RADAR)

for _,DetectedTarget in pairs( list ) do
   if DetectedTarget ~= nil then
       obj = DetectedTarget.object 
       tgt = obj:getTypeName() --the name of one of the detected objects
   end
end

I hope that will work for you.

Edited by Tiramisu
Posted

Thanks so much, that did work. I do need a refresh as you say, it has been years since I even tried scripting and I did not get far at all when I first began, guidance like yours is very helpful.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...