Save variables after closing the app
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Save variables after closing the app
Hello guy, I'm working on a new map and would to save the player score whitout any network connection.
I don't found any solution for that, can you help me ?
I don't found any solution for that, can you help me ?
Re: Save variables after closing the app
Hi Spat',
welcome to the forum!
You need to write the data to disk when the stack closes and read them in again at next appstart.
Store it in
Mobile:
iOs/Android -> specialfolderpath("documents")
Desktop:
Mac -> specialfolderpath("preferences")
Win -> specialfolderpath("support")
Linux -> specialfolderpath("documents")
Best
Klaus
welcome to the forum!
You need to write the data to disk when the stack closes and read them in again at next appstart.
Store it in
Mobile:
iOs/Android -> specialfolderpath("documents")
Desktop:
Mac -> specialfolderpath("preferences")
Win -> specialfolderpath("support")
Linux -> specialfolderpath("documents")
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Save variables after closing the app
Hi.
You can also store the data in a custom property of the stack, which is automatically saved between sessions. This way everything stays inside the stack.
Craig
You can also store the data in a custom property of the stack, which is automatically saved between sessions. This way everything stays inside the stack.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Save variables after closing the app
Hi,
specialfolderpath("documents") works for Mac and Windows too.
Best
Jean-Marc
specialfolderpath("documents") works for Mac and Windows too.
Best
Jean-Marc
https://alternatic.ch
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Save variables after closing the app
On my BBC Model B from 1981 everything evaporates between boots as it has
no hard disk and the OS is stored on a ROM chip.
So I store data on a cassette tape in a cassette player attached to the Beeb via a DIMM socket.
The idea of saving data between uses is at least that old.
no hard disk and the OS is stored on a ROM chip.
So I store data on a cassette tape in a cassette player attached to the Beeb via a DIMM socket.
The idea of saving data between uses is at least that old.
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Save variables after closing the app
Klaus.
We know we cannot save anything in the executable. Are we sure there only a single stack in this app?
I believe all standalones should have another stack file attached to the executable (the "splash" stack"), to allow for easy enhancement, and, er, the ability to save inside the attached stacks.
Craig
We know we cannot save anything in the executable. Are we sure there only a single stack in this app?
I believe all standalones should have another stack file attached to the executable (the "splash" stack"), to allow for easy enhancement, and, er, the ability to save inside the attached stacks.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Save variables after closing the app
Yeah, a stack file can be used. But an LSON file is easier to set up (no changes to architecture needed), and much easier to work with if the app ever transitions to multiple data sets
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: Save variables after closing the app
Klaus wrote: ↑Wed Jul 01, 2020 6:09 pmHi Spat',
welcome to the forum!
You need to write the data to disk when the stack closes and read them in again at next appstart.
Store it in
Mobile:
iOs/Android -> specialfolderpath("documents")
Desktop:
Mac -> specialfolderpath("preferences")
Win -> specialfolderpath("support")
Linux -> specialfolderpath("documents")
Best
Klaus
Is there any method to execute this code when the player close he's app ?
Thanks for the help ^^
Spat'
Re: Save variables after closing the app
Pardon my ignorance, but what on earth is an " LSON file" ?FourthWorld wrote: ↑Wed Jul 01, 2020 7:56 pmYeah, a stack file can be used. But an LSON file is easier to set up (no changes to architecture needed), and much easier to work with if the app ever transitions to multiple data sets
-
- VIP Livecode Opensource Backer
- Posts: 261
- Joined: Sat Aug 16, 2008 9:48 am
- Location: Stockholm, Sweden
- Contact:
Re: Save variables after closing the app
Certainly! In the stack script, put:
Code: Select all
on shutdown
-- Script the saving to local file or stack here
end shutdown
Re: Save variables after closing the app
Hi Craig,
Best
Klaus
yes, we do, but maybe Spat' doesn't?
Yes, but that also requires to copy that namely stack to a place where we have write permission before we can open and save it. The application folder is usually taboo for these kind of things. So depending on the case, saving a little text file with some data in it may be an easier solution, especially for a newbie.
Best
Klaus
Re: Save variables after closing the app
Here is a lesson on how to do this, remember this is just one approach and there are plenty of cats running round with no fur.
http://lessons.livecode.com/m/4071/l/17 ... pplication
http://lessons.livecode.com/m/4071/l/17 ... pplication
Re: Save variables after closing the app
Yes, but saving will fail miserably if the resulting standalone is installed into the platforms application folder:SparkOut wrote: ↑Wed Jul 01, 2020 9:26 pmHere is a lesson on how to do this, remember this is just one approach and there are plenty of cats running round with no fur.
http://lessons.livecode.com/m/4071/l/17 ... pplication
Mac -> Applications
Win -> Programm files...
That lesson, like a lot more, needs to be updated to make sense and to reflect the value of the "new" specialfolderpath("resources")!
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Save variables after closing the app
Sorry, I use the shorthand term so often I sometimes forget not everyone does.bogs wrote: ↑Wed Jul 01, 2020 9:12 pmPardon my ignorance, but what on earth is an " LSON file" ?FourthWorld wrote: ↑Wed Jul 01, 2020 7:56 pmYeah, a stack file can be used. But an LSON file is easier to set up (no changes to architecture needed), and much easier to work with if the app ever transitions to multiple data sets
LSON is an informal shorthand for encoded arrays. I've seen a growing number of others use it, but it has not yet found its way into the mother ship's documentation.
LSON is to LiveCode what JSON is to JavaScript and BSON is to MongoDB, a with-the-grain way to serialize non-serial data like arrays in a robust, efficient way highly optimized for the language.
Given how useful arrays are at runtime, storing and retrieving them has become my go-to format for most things, considering alternatives only when there's some reason LSON won't do what I need.
In this case, I don't know the details of the data so it may be even simpler to just use delimited text, with split/combine.
But since custom props were mentioned, and custom props can be expressed very well as arrays (they pretty much are arrays, with their own serialization bound to the object record on save), using an object-independent array seemed at least worth considering.
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