I was under the impression that script local variables were just like handler-local variables, except that they were available to all handlers within the script.
The handler-local ("temporary") variable doesn't retain its value once the handler is finished. If you run the same handler again, the temp variable is reset (to "empty"). I thought it would be the same with script local variable.
Not so. Not only its value persists after a handler is finished, but even after you leave the card and come back to it (e.g., in case of a card script). I tried out a number of variations.
In this way, the script local variable seems to resemble more the global variable (except for the fact that it is only accessible within a script).
This was a surprise.
Regards,
Sri.
Value persistence of script local variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Value persistence of script local variables
I hope a pleasant one. Script-locals are very powerful in this way, like private globals.sritcp wrote:In this way, the script local variable seems to resemble more the global variable (except for the fact that it is only accessible within a script).
This was a surprise.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Value persistence of script local variables
Yes, and a little disconcerting, too.FourthWorld wrote:I hope a pleasant one.
I found that the value (of the script local) is available to a handler in that script, even if that handler was called (or "sent") from another card.
Thus, a script local value can be accessed from outside that script (essentially, like a global).
I like your "private global" than "script local" as a descriptive.
Thanks,
Sri.
Re: Value persistence of script local variables
You might even take this a step farther, and think of it as a way to store data in a script. Sort of like a private custom property.
Craig Newman
Craig Newman