variables retain value after opening and closing stack file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
xfrios
Posts: 24
Joined: Wed May 25, 2011 11:54 pm

variables retain value after opening and closing stack file

Post by xfrios » Tue May 31, 2011 12:12 pm

In live code it looks like all variables etc retain their values when the application is restarted.

So, if I want to reinitialize all variables in the application (like I often want to after a debug/edit) I have to add code to do that.

Is that correct ?
Is there any other way ?

I am finding it a very strange experience with this data magically persisting even with application run & stop.

I am sure there is a good reason for it. Can someone explain the philosophy behind it? I guess I will not need to do a lot of specific writing to external files if all my application data magically persists.

Is this really the case when the application is deployed to platforms like iOS, or is this behavior only present in the development environment ?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: variables retain value after opening and closing stack file

Post by Klaus » Tue May 31, 2011 12:22 pm

Hi xfrios,

you mean all your local and global and other variables are still there (with their last set value)
when you quit LiveCode and restart it again?

Hmmm, I have been using LiveCode (and its ancestors) for 12 years now and I have never
heard nor experienced this!? 8)

Are you sure there is no initializing routine (e.G. from values of custom properties) going on somewhere?


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: variables retain value after opening and closing stack file

Post by jacque » Tue May 31, 2011 6:44 pm

As Klaus said, variables do not retain their values between launches unless you have initializing scripts that put values into them. If you are seeing something different, tell us how you are setting up your variables. Do you declare them specifically? Are they global, script local, or handler-specific? They aren't defined constants, are they?

I just noticed you say they are in a stack file. If you are closing the stack without quitting the app, and the stack's destroystack property is false, then the stack does not really close. It remains open in the background, but not in the message path, and no variable values will be removed. To really close the stack, set its destroystack property to true, or else have a script issue the command "delete this stack" -- which removes the stack completely from RAM. Note that if your variables are global, they won't be removed until your app quits, though you can manually remove them using the "delete global" command.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

xfrios
Posts: 24
Joined: Wed May 25, 2011 11:54 pm

Re: variables retain value after opening and closing stack file

Post by xfrios » Tue May 31, 2011 9:27 pm

Oops. The largest part of this problem was some of my own runtime initialization getting away from me in a big way. Sorry to bother you with that.

Your comments about stack destruction are useful, thanks!

xfrios
Posts: 24
Joined: Wed May 25, 2011 11:54 pm

Re: variables retain value after opening and closing stack file

Post by xfrios » Wed Jun 01, 2011 12:50 am

Ok, now I have my initialization under control, I can see the remainder.

When I close my stack and exit LiveCode, then re-open LiveCode and load my stack, all the fields are still populated with whatever data they had when the stack was closed. To be more specific:

1. Put "testing" into field fFormText
2. Manually close stack and exit LiveCode
3. Open LiveCode and Open stack
- the field fFormText still contains the data "testing"

I'm sure it's by design, but can you explain a bit about that?

It is probably something very obvious, but I am used to environments where this kind of data does not persist unless I explicitly save and load it. Is this an IDE feature only, or is saving this kind of form/field data just something that the LiveCode Runtime does on all target platforms?

I apologize for my ignorance, but I'm just not getting it.

Thanks!

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: variables retain value after opening and closing stack file

Post by dglass » Wed Jun 01, 2011 2:10 am

xfrios wrote: I'm sure it's by design, but can you explain a bit about that?

It is probably something very obvious, but I am used to environments where this kind of data does not persist unless I explicitly save and load it. Is this an IDE feature only, or is saving this kind of form/field data just something that the LiveCode Runtime does on all target platforms?

I apologize for my ignorance, but I'm just not getting it.

Thanks!
I think it is because of the rather fuzzy relationship between editing mode and browse/run mode.

IMO, it is silly, and the IDE should take care of resetting these items when switching between the two modes. Others (including the runrev folks, it would seem) hold the opinion that this sort of 'resetting/initialization' is the responsibility of the programmer.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: variables retain value after opening and closing stack file

Post by BvG » Wed Jun 01, 2011 2:23 am

stuff is saved, if you save the stack. standalones cannot save itself, so within a standalone you need to save stacks into some other place to benefit from this feature.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: variables retain value after opening and closing stack file

Post by jacque » Wed Jun 01, 2011 7:26 pm

xfrios wrote:Ok, now I have my initialization under control, I can see the remainder.

When I close my stack and exit LiveCode, then re-open LiveCode and load my stack, all the fields are still populated with whatever data they had when the stack was closed. To be more specific:

1. Put "testing" into field fFormText
2. Manually close stack and exit LiveCode
3. Open LiveCode and Open stack
- the field fFormText still contains the data "testing"

I'm sure it's by design, but can you explain a bit about that?
LiveCode will prompt you to save when you close the stack. If you agree, then the field content is saved. Try this:

1. Manually save the stack while the field content is empty.
2. Put "testing" into the field.
3. Close the stack. When LiveCode asks if you want to save, say no.
4. Quit LiveCode. Relaunch it and reopen the stack.

The field should be empty.

If the stack's destroystack property is true, then you don't even need to quit LiveCode. Just closing the stack (and not saving it) will remove it from RAM and when you reopen it, the field should not have any content.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply