Lua Question - missing unit?

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
User avatar
Gunner98
Posts: 5880
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

Lua Question - missing unit?

Post 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
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

RE: Lua Question - missing unit?

Post 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
User avatar
Gunner98
Posts: 5880
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: Lua Question - missing unit?

Post 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
Attachments
Luadoubles.jpg
Luadoubles.jpg (32.91 KiB) Viewed 76 times
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

RE: Lua Question - missing unit?

Post 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.
User avatar
Gunner98
Posts: 5880
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: Lua Question - missing unit?

Post by Gunner98 »

Roger - thank you very much. Appreciate the help.

B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Post Reply

Return to “Mods and Scenarios”