First:
Use the Global.DoWaitFor(object_id, nnn);
-- This function may be used to wait for some object or to find an object. See Global.DoWaitFor for more details.
So if you have some object (such as text label, button and so on) available for the current dialog you may 'wait' for it for small amount of time. If it is not found the the dialog does not exist. For example:
if(Global.DoWaitForWindow('Error Message', 'regex:.*'))
{
// Actions if the window is found
}