[comp.sys.mac.hypercard] One-time-per-boot Script

dave@lsuc.on.ca (David Sherman|LSUC|Toronto) (05/04/90)

aland@chaos.cs.brandeis.edu (Alan D Danziger) writes:
>>  What I was trying to accomplish in having a bit of code run only
>>..

>Here's a suggestion.  Why don't you put into a hidden field on your
>stack a message saying whether the routine was run (put it into the
>openStack handler) and edit the Home card's "domenu Quit" or whatever
>the quit handler might be called (It's been quite a while since I used
>HC to program) to clear the flag.  This way, whenever the stack is
>opened, it will check this 'flag', and whenever HC is quit, it will be
>reset.

Much better would be to use a global variable.  Using a field
will fail if Hypercard crashes (or, say, a power failure zaps
your Mac while running Hypercard); the field will still indicate
the startup routine was run when you next start up.  And, for that
matter, you can leave a stack with lockMessages set to true and get
things confused.

Put a "global StartedStackXYZ" into the stack script.  I've found that
you get errors if you try to compare an undefined global against
anything except "empty", but "empty" works.  So, in the openStack
handler, do:
	if StartedStackXYZ is empty then
	  put true into StartedStackXYZ
	  <do your one-time-per-boot code here>
	end if

(Customize XYZ to the name or purpoer of your stack.)

David Sherman
Toronto
-- 
Moderator, mail.yiddish
{ uunet!attcan  att  utzoo }!lsuc!dave          dave@lsuc.on.ca