One thing that helps here is calling everything from the window rather than starting a script and then asking for input part way through. Even if you don't need user input right away, you could open a window that says 'Starting...', and then in the On Open() script put everything you have before the window today, but with window or local scoped variables. With long scripts this can get out of hand, but then you might consider breaking those into different functions that are defined before the window, or even in different files.
As an example , the Validation Column for time series process data add-in is written this way. Note how UpdateUI is defined in this script on line 274 before New Window is called (sorry if that breaks for future readers), and then it is called when a button is pressed on line 670 and when other fields are updated.
Note that this function calls window: variables all over the place - that function's primary purpose is updating the user interface. For most add-ins I do not recommend this, pass all of the info it needs as arguments/parameters and then use all local variables inside the function and only pass results back.