* Makes calls for GetAmmo() and GetVec3() safer with pcall()

* Small docu fix Ben-Gurion
This commit is contained in:
Applevangelist
2023-06-13 08:39:56 +02:00
parent 12f260e857
commit 241b2beee1
3 changed files with 24 additions and 16 deletions

View File

@@ -237,22 +237,23 @@ end
-- @return DCS#Vec3 The 3D point vector of the POSITIONABLE.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVec3()
local DCSPositionable = self:GetDCSObject()
if DCSPositionable then
local vec3 = DCSPositionable:getPoint()
if vec3 then
local status, vec3 = pcall(
function()
local vec3 = DCSPositionable:getPoint()
return vec3
end
)
--local vec3 = DCSPositionable:getPoint()
if status then
return vec3
else
self:E( "ERROR: Cannot get vec3!" )
self:E( { "Cannot get Vec3 from DCS Object", Positionable = self, Alive = self:IsAlive() } )
end
end
-- ERROR!
self:E( { "Cannot GetVec3", Positionable = self, Alive = self:IsAlive() } )
self:E( { "Cannot get the Positionable DCS Object for GetVec3", Positionable = self, Alive = self:IsAlive() } )
return nil
end