Syntax for an exist or does not exist?
Posted: Thu Jul 15, 2021 10:27 am
apologies, got the whole emulate console thing eventually after much searching and finding soemone elses code who does know what they're doing.....
Tool_EmulateNoConsole(true)
ScenEdit_AddSide({name='test'})
local i= 1, 8
local u = ScenEdit_GetUnit({side='B', name='Marauder #'..i})
if(u ~= nil) then
--print('u was defined')
ScenEdit_MsgBox ('Marauders are present',0)
else
--print('u not defined')
ScenEdit_MsgBox ('Marauders are being added',0)
for planes = 1, 8, 1 do
ScenEdit_AddUnit({type = 'Air', unitname = 'Marauder #'..planes, loadoutid = 5347, dbid = 1404, side = 'B', base='B AIRBASE'})
end
for i=1,8 do ScenEdit_AssignUnitToMission('Marauder #'..i, "Intercept") end
end
ScenEdit_RemoveSide({name='test'})
Tool_EmulateNoConsole(false)
Ok so I repeatedly failing with this, and pretty incompetent at best so your collective patience and help is much appreciated...
I want a group of fighters to effectively re-spawn at timed intervals but to limit the numbers and only re-spawn if all 8 have been shot down or don't exist to avoid a horde accumulating. (I'm calling them Marauder 1 through 8)
So once all 8 are gone after X hrs they'll reappear.
I am ok with the timer, etc but am failing on the whole LUA for check the OPFOR units 1-8 exist and most importantly what is the code for doing something if they don't exist.
Logic would say its a case of
1. Check the unit exists. YES/NO i.e ScenEdit_GetUnit({Side='B', Name="Marauder #"..num}) ~= nil then
2. If exist do nothing.
3. elseif do XYZ
But as soon as it fails to find the unit "Marauder - 1 to 8" it just fails and wont move on to the next action.
so if
if ScenEdit_GetUnit({Side='B', Name="Marauder #"..num}) ~= nil then -- confirms the unit exists
What is the code for a negative result?
Regards
K
Tool_EmulateNoConsole(true)
ScenEdit_AddSide({name='test'})
local i= 1, 8
local u = ScenEdit_GetUnit({side='B', name='Marauder #'..i})
if(u ~= nil) then
--print('u was defined')
ScenEdit_MsgBox ('Marauders are present',0)
else
--print('u not defined')
ScenEdit_MsgBox ('Marauders are being added',0)
for planes = 1, 8, 1 do
ScenEdit_AddUnit({type = 'Air', unitname = 'Marauder #'..planes, loadoutid = 5347, dbid = 1404, side = 'B', base='B AIRBASE'})
end
for i=1,8 do ScenEdit_AssignUnitToMission('Marauder #'..i, "Intercept") end
end
ScenEdit_RemoveSide({name='test'})
Tool_EmulateNoConsole(false)
Ok so I repeatedly failing with this, and pretty incompetent at best so your collective patience and help is much appreciated...
I want a group of fighters to effectively re-spawn at timed intervals but to limit the numbers and only re-spawn if all 8 have been shot down or don't exist to avoid a horde accumulating. (I'm calling them Marauder 1 through 8)
So once all 8 are gone after X hrs they'll reappear.
I am ok with the timer, etc but am failing on the whole LUA for check the OPFOR units 1-8 exist and most importantly what is the code for doing something if they don't exist.
Logic would say its a case of
1. Check the unit exists. YES/NO i.e ScenEdit_GetUnit({Side='B', Name="Marauder #"..num}) ~= nil then
2. If exist do nothing.
3. elseif do XYZ
But as soon as it fails to find the unit "Marauder - 1 to 8" it just fails and wont move on to the next action.
so if
if ScenEdit_GetUnit({Side='B', Name="Marauder #"..num}) ~= nil then -- confirms the unit exists
What is the code for a negative result?
Regards
K