Page 1 of 1

Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 11:00 am
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

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 11:21 am
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"

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 2:26 pm
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

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 2:48 pm
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

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:01 pm
by MaxV
My solution works also in standalone applications. :P

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:20 pm
by dunbarx
Max.

Certainly. Just options...

Craig

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:22 pm
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)

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:36 pm
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.

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:38 pm
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:

Re: Saving variable when a stack is closed

Posted: Fri Dec 13, 2013 5:49 pm
by Klaus
HA! :D


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