Wrap getLife with pcall to handle error where unit is lost (#3390)

This commit is contained in:
zhexu14 2024-05-25 15:09:18 +10:00 committed by GitHub
parent cbf5f5ed90
commit 11304542bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,9 +151,11 @@ end
function update_hit_points(event)
local update = {}
update.name = event.target:getName()
update.hit_points = event.target:getLife()
unit_hit_point_updates[#unit_hit_point_updates + 1] = update
write_state()
get_life_success, update.hit_points = pcall(event.target.getLife, event.target)
if get_life_success then
unit_hit_point_updates[#unit_hit_point_updates + 1] = update
write_state()
end
end
activeWeapons = {}