ScenEdit_RefuelUnit works but getting error

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
robotsanta77
Posts: 8
Joined: Wed May 06, 2020 2:43 pm

ScenEdit_RefuelUnit works but getting error

Post by robotsanta77 »

I'm trying to make a script that will make all the air units in a mission go and refuel at a specific refuel mission. The problem I'm having is that when ever I try the ScenEdit_RefuelUnit function, I get a "ERROR: Object reference not set to an instance of an object.". The weird things is that even though it is popping an error the unit being told to refuel is still getting the order the refuel. The problem for me is that if I'm trying to tell multiple aircraft to refuel it will error out of the script on the first aircraft and only tell the first aircraft to refuel. An example of something similar to what I'm using would be like this:

for a,b in pairs(ScenEdit_GetMission('YourSide', 'YourStrikeMission').unitlist) do
ScenEdit_RefuelUnit({side = 'YourSide', guid = b, missions = {'YourRefuelmission'}})
end

In this case, it will give the first unit it loops through the order to refuel but it will error on the first loop and stop before it can give the order to all the units in the mission unitlist. Am I using an improper format for the ScenEdit_RefuelUnit?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: ScenEdit_RefuelUnit works but getting error

Post by KnightHawk75 »

May need to see the specific environment in which it's running to help you.

The following is what I use if I don't care if the order is given twice when groups are involved in the list (ie guids are in the list both for the members and the groups associated with those members if there area any), it's basically the same code but with error checking on all the scen_ calls.
If you want to avoid it being issued twice let me know I have a version with restrictions though probably unrelated to your issue.

Code: Select all

gKH={}; gKH.Missions={};
 function gKH.Missions:refuelAllMissionMembersToSpecificMissionTankers(mside,mname,rside,rmissions) 
     local fn = "refuelAllMissionMembersToSpecificMissionTankers(): "
     local retval,m = pcall(ScenEdit_GetMission,mside, mname)
     if ((retval == true and m ~=nil) and m.unitlist ~= nil) then
         local counter = 0;
         local msg;
         for k,v in pairs(m.unitlist) do
             retval,msg = pcall(ScenEdit_RefuelUnit,{side = rside, guid = v, missions = rmissions})
             if (retval == true) and msg=="" then
                 counter = counter + 1;
                 print(string.format("%s Refuel action triggered for guid %s",fn,tostring(v))); --dbg
             else   --debugging
                 print(string.format("%s Refuel action failed for guid %s  ErrMsg: %s",fn,tostring(v),tostring(msg)));
             end 
         end 
         print(string.format("%s Completed triggering refuel action for all member of mission %s  count: %s",fn,tostring(mname),tostring(counter)));
     else 
         print(fn .. "Could not obtain specified mission or mission members table was nil. aborted.");
     end
 end
 gKH.Missions:refuelAllMissionMembersToSpecificMissionTankers("Blue","Blue_CAP1","Blue",{'Blue_AAR1'})

I don't get any ObjectRefs errors when using that and I've never noticed a flight\unit not get it's refuel order, but again maybe it's something specific to your scene or mission types? The attached is simple scene with special action showing the above in action without errors.
Attachments
TestRigLU..21db488.zip
(53.76 KiB) Downloaded 5 times
Post Reply

Return to “Lua Legion”