Nil unit problem
Posted: Sat May 02, 2020 11:34 am
So I want the game to be able to detect if a unit exists or not to allow an action to go forward. I used this code at first
local unit = ScenEdit_GetUnit({ guid='w7zxl3-0hluonqpphh5v'})
if unit == nil then
local current score = ScenEdit_GetScore('United States')
local newscore = current score + 500
ScenEdit_SetScore('United States',newscore,'Hostages Exfil')
ScenEdit_MsgBox('Admiral, \n\n Thunder reports the hostages are feet wet', 1)
else
ScenEdit_MsgBox('Hostages are still in AO. You need to get them on a helicopter', 1)
end
But if the unit is not present then the action fails because the GUID I used does not exist (because the unit has been picked up)
I tried
if ScenEdit_GetUnit({ guid='w7zxl3-0hluonqpphh5v'}) == nil then
local current score = ScenEdit_GetScore('United States')
local newscore = current score + 500
ScenEdit_SetScore('United States',newscore,'Hostages Exfil')
ScenEdit_MsgBox('Admiral, \n\n Thunder reports the hostages are feet wet', 1)
else
ScenEdit_MsgBox('Hostages are still in AO. You need to get them on a helicopter', 1)
end
but that failed also. Both times the console told me I needed to select a valid GUID or unit_name. Is there a work around?
local unit = ScenEdit_GetUnit({ guid='w7zxl3-0hluonqpphh5v'})
if unit == nil then
local current score = ScenEdit_GetScore('United States')
local newscore = current score + 500
ScenEdit_SetScore('United States',newscore,'Hostages Exfil')
ScenEdit_MsgBox('Admiral, \n\n Thunder reports the hostages are feet wet', 1)
else
ScenEdit_MsgBox('Hostages are still in AO. You need to get them on a helicopter', 1)
end
But if the unit is not present then the action fails because the GUID I used does not exist (because the unit has been picked up)
I tried
if ScenEdit_GetUnit({ guid='w7zxl3-0hluonqpphh5v'}) == nil then
local current score = ScenEdit_GetScore('United States')
local newscore = current score + 500
ScenEdit_SetScore('United States',newscore,'Hostages Exfil')
ScenEdit_MsgBox('Admiral, \n\n Thunder reports the hostages are feet wet', 1)
else
ScenEdit_MsgBox('Hostages are still in AO. You need to get them on a helicopter', 1)
end
but that failed also. Both times the console told me I needed to select a valid GUID or unit_name. Is there a work around?