saveGlobals

  how to exclude some globals to be voided by clearglobals?
globals clearglobals




  clear only some globals
>There is a way to clear globals that I want to clear leaving the others
>untouched?
>I know that with clear globals you delete all the globals, but what I have
>to do if I want some globals to stay.
>
>Thanks for any advice
>
>Teo

Depends. 
If you have just some global variables you want to preserve in a multitude of 
vars you wish to get rid off, set those lucky few to local vars, clearglobals 
and reset the few globals afterwards, as in

on clearMostoftheGlobals
  global gMustHave1, gReallyNeedIt2
  set mustHave = gMustHave
  set reallyNeedIt = gReallyNeedIt
  clearglobals
  set gReallyNeedIt = reallyNeedit
  set gMustHave = mustHave
end

If on opposite, you have just some globals you want to kill or rather, reset to 
their default value, use a ResetVariables handler like Joshua proposed already.

If both alternatives look unpractical since there are just too many single variables 
to treat them propper individually the key to an answer may lie in the question, whether 
indeed you need a bazillion of variables in order to store a bazillion of values. In a 
larger project a set of different property lists with different purpose and lifetime each 
may help. 
You may have variables used only in a specific situation. Instead of putting them each into 
globals you could put them into a property list gLpShortTermVar. You just reset that property 
list whenever you leave a "specific situation" and  60% of your global soup is away.
You may have variables which are valid only while your in a given movie and need to be 
reinitialized as soon as the user changes to another movie of your project. Put them into a 
property list gLpThisMovieVar and reset that list before you actually 'go movie "theNext"'. etc.
Now you may have reduced the number of globals from 150 to 5, but accessing the variables in those 
lists is a bit too verbose.
If you are bored by typing all that getaprop/setaprop stufff again and again you might want to 
write some functions to access the data more easy, like 

on getAShortTermVar theVar
  global gLpShortTermVar
  if not voidP(theVar) then return getaProp(gLpShortTermVar,theVar)
end

on setAShortTermVar theVar,theVal
  global gLpShortTermVar
  if not voidP(theVar) then setaProp gLpShortTermVar,theVar,theVal
end


Other ways to save globals from being killed by clearglobals include storing them in object or 
script properties or in the windowlist, in the system variable version or in an alert hook object.

Home shock + cgi Bits 'n pieces Director Lingo Shocklets Contact










pageID=l_saveGlobals