Page 1 of 1

A command to clear all globals

Posted: Fri Mar 02, 2012 10:19 pm
by tonymac
I sure could use a single command that would "ClearAllGlobals". Wow... that's it, clearGlobals. That would make my coding and debugging life so much more simple in so many ways.

Thanks.

Re: A command to clear all globals

Posted: Fri Mar 02, 2012 11:29 pm
by Gene
Try looking up the keyword "Globals" in the dictionary. There is both a command, and a function, described that are supposed to return a list of all globals. I would try a simple repeat routine that rampages through the list and deletes them one at a time from start to finish. It seems awkward compared to a simple built-in "clearGlobals" command, but you could always put your script into a custom function called "clearGlobals" and keep it to drop into each new project, ready to go.

A brief look at the documentation suggests that it would be a good thing to check out the other references pertaining to deleting variables before called it done.

Gene

Re: A command to clear all globals

Posted: Fri Mar 02, 2012 11:41 pm
by mwieder
Additionally, I avoid problems with global variables by avoiding the use of global variables.

If you absolutely need this you might try

before doing anything with global variables:

Code: Select all

put the globals into sGlobals
then when you want to clean them

Code: Select all

on clearGlobals
  put the globals into tGlobalList
  repeat for each line tGlobal in tGlobalList
    if tGlobal is not among the lines of sGlobals then
      global tGlobal
      delete variable tGlobal
    end if
  end repeat
end clearGlobals