Saving variable when a stack is closed

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
TheApexEffect
Posts: 6
Joined: Mon Nov 18, 2013 8:34 pm

Saving variable when a stack is closed

Post by TheApexEffect »

Hey all, I was wondering if there is any way to stop a variable from being deleted when a stack is closed. For instance in my project I am using a variable called playcounter, this variable is supposed to count how many times the program has been run but any values it holds are deleted when the stack is closed. Any help will be greatly appreciated and thanks in advance
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Saving variable when a stack is closed

Post by MaxV »

You need to save in an external file. I suggest you to add:

Code: Select all

on preOpenStack
  set itemDel to "/"
  set the defaultFolder to item 1 to -2 of (the effective fileName of this stack)
end preOpenStack
Then you can add:

Code: Select all

put playcounter into URL "file:./playcounter"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Saving variable when a stack is closed

Post by Klaus »

Hi TheApexEffect,

Max' solution may work in the IDE, but probably NOT in any standalone because of missing write permissions!
Better use a suitable "specialfolderpath()" for the platform you want to write your info!


Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Saving variable when a stack is closed

Post by dunbarx »

Is this indeed for a standalone? If it is, use the "splash screen" method to allow your main working stack to be able to save data. If not, set a custom property to hold the value.

Craig Newman
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Saving variable when a stack is closed

Post by MaxV »

My solution works also in standalone applications. :P
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Saving variable when a stack is closed

Post by dunbarx »

Max.

Certainly. Just options...

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

Re: Saving variable when a stack is closed

Post by Klaus »

MaxV wrote:My solution works also in standalone applications. :P
Not on desktop, only if the current user has ADMIN permissions!
An "average" user cannot write into the platform specific "Applications" folder on Mac and Win!

Not to talk about -> specialfolderpath("engine") on mobile, which is exactly what your script will point to 8)
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Saving variable when a stack is closed

Post by MaxV »

Klaus wrote:
MaxV wrote:My solution works also in standalone applications. :P
Not on desktop, only if the current user has ADMIN permissions!
An "average" user cannot write into the platform specific "Applications" folder on Mac and Win!

Not to talk about -> specialfolderpath("engine") on mobile, which is exactly what your script will point to 8)
I use that tecnique on Windows Xp, Windows Vista, Windows 8 and Linux every day and it works. :shock:
On Linux I am not root.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Saving variable when a stack is closed

Post by MaxV »

Now I understood what you means.
My applications are never in system protected folders, my applications are located in user folders like "Documents". :lol:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Saving variable when a stack is closed

Post by Klaus »

HA! :D


Your message contains 6 characters. The minimum number of characters you need to enter is 10.
Post Reply