Parel803
Posts: 579
Joined: 10/10/2019 From: Netherlands Status: offline
|
I like this function and tried it out, works great. Want it to use with pre-determined units. But I'm doing something wrong. tried to change accordingly the orders but got: 'Please select one or more units first.' I made this: gBDude={} gBDude.SceneGlobals={} gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits={ {name='F 802 De Zeven Provinciën', guid='P7ML9T-0HMECC07850U3'}, {name='P 840 Holland', guid='P7ML9T-0HMED2D1QP4KD'}, {name='F 930 Leopold I [Karel Doorman]', guid='P7ML9T-0HMED2D1QP8E0'} }; local function processSelectedUnits(pcolor) local sUnits=gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits local tbl ={}; if(sUnits.units ~=nil) then local u,g; local counter=0; for k,v in pairs(sUnits.units) do --loop though selected unit table u = ScenEdit_GetUnit({guid=v.guid}); --get the unit. if ((u~=nil) and u.type ~='Group') then --are we valid and not a group? table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1; elseif((u~=nil) and u.type =='Group') then --are we valid and also a group? g = u.group.unitlist; --simply array of unit guids of members. for l,m in pairs(g) do u = ScenEdit_GetUnit({guid=m}); --get the unit. if ( (u ~= nil) and u.type ~='Group') then -- are we valid and not also another group? table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1; else ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(m), 1); end u=nil; end else ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(v.guid), 1); end u=nil; end ScenEdit_MsgBox(string.format('Completed fuel report on %s units',tostring(counter)), 1); else ScenEdit_MsgBox('Please select one or more units first.', 1); end sUnits=nil; return tbl; end It all goes beyond my comprehension, hope you spot my mistake. best regards GJ and best wishes for 2022
|