From: Melbourne, Australia
This is from the Lua Documentation:
Note: Due to how errors are now handle from SR7, if a command fails in the console window, it will show an error. If the command runs outside the console (as in an event script), it will not fail with a visible error but return a nil or or some other value. One issue with commands running in an event is that sometimes they fail with an in-game message that actually stops the rest of the script from running. Now, these event scripts will run without any in-game message showing, and the designer should check the result of the command and handle any error condition, and let the remaining script run as needed.
My intent is have all command errors behave in the same fashion in the console window; and the command errors outside a console behave without stopping the script. Which requires the designer to cater for the specific error conditions.
To emulate the expected outcome from an event, put 'Tool_EmulateNoConsole(true)' at the start of the script to be tested; it is not required in the event code as the script is already not running in a console.
Note also, that the Lua history log should also record the event script errors.
Run the command 'Tool_EmulateNoConsole(true)' at the start of the script in the console so that the GetUnit() will return nil, and the script should work.
If the script is part of an event action, then the 'Tool' command is not needed. It just emulates what would happen in a non-console script.