Initializing local properties

David Bovill david.bovill at
Wed Apr 15 14:39:42 EDT 2009

2009/4/15 Richard Gaskin <ambassador at>

While we wait for the ability to initialize vars from a function call, a
> single Init handler in a behavior script may do the trick for now.
> If you used a script-local var as a flag to see if it's been initialized,
> you could ensure it's initialized only once even if called from a
> preOpenCard handler:
> local sInited
> on preOpenCard
>  if sInited is empty then
>    -- do initialization stuff
>    put true into sInited
>  end if
>  pass preOpenCard
> end preOpenCard

Yes - but as in the example I gave the custom property is being called from
outside of the current stack - so no preOpenCard message is sent - and
unfortnuately we don't have any "load" type messages that we can trap when a
stack gets loaded into memory - only when it is opened.

I want the properties I define to be as close as possible to 100% bullet
proof - and callable from aywhere in the environment. A use case for
instance would be you have a library of a hundred view widgets - they are ot
laoded into memory but sitting on the local hard disk, and indexed in the
stackfiles. A script want to be able to get or set one of the views behavior
in a natural syntax - ie:

put the long id of grp 1 of stack "Outliner" into someView
> if the view_Type of someview is "tree" then addToIndex
> copy someView to this card

And not care if is already open or this is the first time it is opening -
there is nothing you can do about this other than load everything into
memory on startup - or call functions and getprops dynamically (which loses
the elegance and speed advantages of doing it once and loading it into a
local variable.

More information about the use-livecode mailing list