Script locals in library stack script

J. Landman Gay jacque at hyperactivesw.com
Fri Feb 10 15:22:02 EST 2017


On 2/10/17 5:56 AM, Bob Hall via use-livecode wrote:
> I’ve been wondering this myself. I’m going to try to create a recipe
> but it looks like the TTL of script local variables is different than
> what I thought I knew it to be. I “think” I started see this behavior
> about 8.1.0-ish timeframe but not sure.
>
> In the past few months I started to put everything into properties as
> I found that my understanding of how script local variables behaved
> was different then how they do.

I have set the LC preference to preserve variables. In the past I have 
rarely seen a script local lose its value, and never if there has been 
no script compile. I don't know exactly when it started but I was in 
8.1.3 rc 1 when I noticed it. I spent two days trying to fix the 
problem, eventually gave up and worked around it. The extremely odd 
thing was that the script had three script locals, and only one of them 
lost its value. The other two were fine. It was impossible to track down.

Here is what I was doing:

Stack Main has a substack "InternetLib" that contains all handlers that 
deal with server connections. It is put in use when Main opens. 
InternetLib handles server queries and returns the retrieved data. That 
all works fine. It also has a "setter" handler that can be used to store 
data in a script local variable in its own script, and a "getter" 
handler to return data from the script local.

What happened:

1. Stack Main calls InternetLib to do a query.
2. Stack Main manipulates the returned data, parses out what it needs, 
and calls the "setter" handler to store it in the script local "sVarA" 
in InternetLib.
3. Immediately after the handler ends, Stack Main calls InternetLib to 
do a second query.
4. Stack Main uses the returned data and calls the "setter" handler to 
store the value in InternetLib script local "sVarB".
5. Later, stack Main tries to retrieve a value from sVarA. sVarA is empty.
6. Retrieving data from sVarB is always available.

The third script local, sVarC, always retains its value. It is not 
involved with the above process, it is set earlier when Main is opened.

When tracing through the handlers, it appears that sVarA loses its value 
some time between the first query and the second. What I need to do is 
find a way to track sVarA to see when it changes. There used to be a way 
to do that but I can't remember how, or else I forgot it on purpose 
because it didn't work.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com





More information about the use-livecode mailing list