Blind squirrel succeeds again: Adds Wait statement

I have a text editor object for editing a variable. If the user enters an invalid number, I wanted to delete the entry, issue a notification, and keep that object open. Earlier I had developed a custom function to test if a variable was a valid number (using the regex expression that Jim posted several weeks ago). So I wrote this code for the text editor, which is triggered on tab or end:

if  goodfpn(fg11305)=0  //goodfpn( returns true (i.e. -1) if the variable 
        is a valid number; or false (i.e. 0) if it is not)
    nsnotify "Invalid number, try again!"
    fg11305=""
    showvariables fg11305
    wait 0
    objectaction "fg11305","open"  //The object name is the same as the variable
endif

However, originally there was no wait statement. The procedure worked except for the objectaction statement. The open object just moved to the next object as it normally does upon tabbing. So finally, I added a wait 0 statement and voilà, the open object remains on (or returns to) the same text editor. I have no idea why this works, but it did.

That makes sense – the object isn’t necessarily closed yet, so you can’t reopen it. The wait ensures that Panorama has time to close it before you try to reopen it.