Page 1 of 1

Lua Question - missing unit?

Posted: Thu Jun 09, 2016 8:52 pm
by Gunner98
Hi guys

Need some more Lua help

To delete/change sides/assign mission etc for a complete squadron with similar names, I'm using something CK helped me with a while back:

for i=1,24 do ScenEdit_DeleteUnit({Side='Test', Name="58 FS 'Gorillas' #"..i,}) end


Which works really well - until there is a missing unit! Say #8 (of 24) has been killed; Lua will carry on with the function until #7 then return an error message and stop.

Is there a way to bypass missing units in this function so that Lua skips the missing dude, and carries on with the rest in the series?

Thanks

B

RE: Lua Question - missing unit?

Posted: Fri Jun 10, 2016 1:35 am
by ckfinite
Write

for i=1,24 do
if ScenEdit_GetUnit({Side='Test', Name="58 FS 'Gorillas' #"..i,}) ~= nil then
ScenEdit_DeleteUnit({Side='Test', Name="58 FS 'Gorillas' #"..i,})
end
end

RE: Lua Question - missing unit?

Posted: Fri Jun 10, 2016 8:04 am
by Gunner98
Thank you sir - works like a charm

Another quick one if I might:

When adding AC of a different type but in the same unit the game defaults to a naming convention of '...#1' etc (see clip)

Have assumed that if I want to do the same trick, I'll need to go and rename them to give each a unique identifier - or can Lua do something about that?

Image

RE: Lua Question - missing unit?

Posted: Sat Jun 11, 2016 1:58 am
by ckfinite
Sorry, didn't see this for a bit.

There are unique identifiers, GUIDs, but it's not really easy to get them from units in airbases (though you can get them from unhosted units). The best bet IMO is to do it manually.

RE: Lua Question - missing unit?

Posted: Sat Jun 11, 2016 6:59 am
by Gunner98
Roger - thank you very much. Appreciate the help.

B