Functions - How to?
Posted: Sun Jan 28, 2018 2:18 pm
Ok, so I think I figured out my question about resetting cap code. Here is what I came up with
local acount=0
for i=1,12 do
ScenEdit_AssignUnitToMission('Sundowner #'..i, 'America CAP')
if acount<4 then
unit=ScenEdit_GetUnit({side='NATO', name="Sundowner #'..i})
if unit.condition_v=='Airborne' then
acount = acount+1
end
else
unit=ScenEdit_GetUnit({side='NATO', name='Sundowner #'..i})
if unit.condition_v=='Airborne' then
ScenEdit_SetUnitSide({side='NATO', name='Sundowner #'..i, RTB='true'} )
end
end
end
No I need to run this code on five different missions and reasoned that it would be best to set this up as a function. The problem is that I am unsure how to execute the creation, saving and loading of a function. I know the function needs to be saved to the lua library in the CMNAO folder. Then an "include" line needs to be added to a scenario start event
So my questions are:
1. How do I save the function to the lua library?
2. how do I add that library to the scenario?
3. If I publish this scenario, how do I add the needed function to the export/import so that other players have access to this function
As always, thank you in advance for the help
local acount=0
for i=1,12 do
ScenEdit_AssignUnitToMission('Sundowner #'..i, 'America CAP')
if acount<4 then
unit=ScenEdit_GetUnit({side='NATO', name="Sundowner #'..i})
if unit.condition_v=='Airborne' then
acount = acount+1
end
else
unit=ScenEdit_GetUnit({side='NATO', name='Sundowner #'..i})
if unit.condition_v=='Airborne' then
ScenEdit_SetUnitSide({side='NATO', name='Sundowner #'..i, RTB='true'} )
end
end
end
No I need to run this code on five different missions and reasoned that it would be best to set this up as a function. The problem is that I am unsure how to execute the creation, saving and loading of a function. I know the function needs to be saved to the lua library in the CMNAO folder. Then an "include" line needs to be added to a scenario start event
So my questions are:
1. How do I save the function to the lua library?
2. how do I add that library to the scenario?
3. If I publish this scenario, how do I add the needed function to the export/import so that other players have access to this function
As always, thank you in advance for the help