SafeGetUnit (pcall example)
Posted: Sat Mar 13, 2021 9:52 am
OK,
Apparently, Lua code execute by events will terminate the event execution if there is an error, like ScenEdit_GetUnit fails...
I was seeing this on the forums, but did not pay much attention to it...to my regret, as I am now writing substantial event driven Lua code...
Since most of my events deal with a unit, I though a SafeGetUnit function might be helpful (too prevent repeatedly writing pcall, and potential errors with each instance...)
The function is provided in the attachment, along with test code that proves that the function behaves as described.
If you find it useful, use it.
Apparently, Lua code execute by events will terminate the event execution if there is an error, like ScenEdit_GetUnit fails...
I was seeing this on the forums, but did not pay much attention to it...to my regret, as I am now writing substantial event driven Lua code...
Since most of my events deal with a unit, I though a SafeGetUnit function might be helpful (too prevent repeatedly writing pcall, and potential errors with each instance...)
The function is provided in the attachment, along with test code that proves that the function behaves as described.
If you find it useful, use it.