Best Practices using globals vs. custprops?
J. Landman Gay
jacque at hyperactivesw.com
Fri Jun 22 14:12:46 EDT 2007
Stephen Barncard wrote:
> Speaking of persistence, has anyone been using the "Variable
> preservation by default" feature in Preferences-->Script Editor--> that
> showed up a few version ago?
>
> How would this be used, and does anybody actually turn this on?
>
It was turned on by default when it first was implemented and I've left
it on ever since. It's handy. Without it, editing a script will empty
the values of all script-local variables. If your script relies on those
values to function, handlers will fail after editing unless you reset
the script local values.
With the new property turned on, the script locals retain their values
after a script edit and you don't have to reset anything.
For example:
local myVar
on opencard
put 1 into myVar
...
end opencard
on otherHandler
add 1 to myVar
end otherHandler
If I edit the script without preservation turned on, "myVar" will lose
its value and "otherHandler" will throw an error the next time it runs.
With the preservation turned on, myVar retains its current value
throughout any editing session.
I used to have to preface handlers with something like this:
if myVar = "" then put 1 into myVar
just so I could edit without interruption. Now I don't have to.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list