Save custom attributes in standalone

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

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Save custom attributes in standalone

Post by Da_Elf » Tue Jun 13, 2017 9:33 pm

if i want to have some settings save for the next time i open the program without saving them to an external file how can i do it?

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Save custom attributes in standalone

Post by SparkOut » Tue Jun 13, 2017 10:33 pm

Simple answer: you can't. A standalone cannot modify itself. You can easily write to an external file on exit, and read in on starting up again. The external file can be a livecode stack too.
Additionally you can extend this idea to have a standalone that is just a launcher for your application which is a native livecode stack. Look up "splashstack technique" for more specifics.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Save custom attributes in standalone

Post by dunbarx » Tue Jun 13, 2017 10:46 pm

Hi.

First you must know that the executable cannot save to itself. So any such settings must be stored either in another stack or in an external file. Are you familiar with both of these methods?

Craig Newman

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Save custom attributes in standalone

Post by Da_Elf » Tue Jun 13, 2017 11:07 pm

looks like it will have to be external file i guess

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Save custom attributes in standalone

Post by dunbarx » Tue Jun 13, 2017 11:58 pm

I always use the "splash" stack method, using external files seldomly

Invariably it is in the "working" stack(s) where I store properties and other data, and these are saved between sessions. I find this more comforting and accessible than using external files.

Unless I misunderstand what you meant by:
looks like it will have to be external file i guess
you can almost certainly keep whatever settings you like within your (working) stack.

Craig

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Save custom attributes in standalone

Post by Da_Elf » Wed Jun 14, 2017 12:50 am

Ok. So my program has need of a database. When the program first runs if it can't find a database, it will go to a card where the user puts in his database name, username and password. The database is then created and I want those settings saved so that whenever the program runs it has the right database name, username and password to use. I would love it if they were saved in the program as opposed to an external file

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Save custom attributes in standalone

Post by dunbarx » Wed Jun 14, 2017 5:32 am

OK.

So save all those preferences in a custom property of the stack. This is simple and straightforward unless we still do not grok the "Splash" thing.

Craig

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Save custom attributes in standalone

Post by Klaus » Wed Jun 14, 2017 11:28 am

Hi friends,

please don't forget that if the app/exe has been installed into the "correct" place ("Applications" on Mac and "Programm files..." on Windows)
only users with ADMIN permissions are allowed to write (= save a stack or anything else) in that directory!


Best

Klaus

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Save custom attributes in standalone

Post by Da_Elf » Wed Jun 14, 2017 12:48 pm

dunbarx how do i save to a stack AFTER the program has been compiled to a standalone is the question

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Save custom attributes in standalone

Post by dunbarx » Wed Jun 14, 2017 1:51 pm

You make a small stack that may have absolutely nothing on it or in it. Name it "splash".

In the standalone settings for this stack you can add other stack files to your heart's content . Those stack files contain "working" stacks (and substacks).

The stack "splash", upon opening, navigates to one or more of those other stacks. It can hide itself. ALL those other stacks can save their data between sessions. So the splash stack becomes the executable, "carrying" along with it other stacks that actually do the stuff you likely worked in the IDE.

In the IDE, you might liken it to the engine (LC itself) being the executable and any old stack you mess around with being the "working' stack. This analogy maps to a standalone, in that the splash stack is LC, and its attached stack files are the ordinary stacks that you play with.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9838
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Save custom attributes in standalone

Post by FourthWorld » Wed Jun 14, 2017 3:43 pm

Da_Elf wrote:Ok. So my program has need of a database. When the program first runs if it can't find a database, it will go to a card where the user puts in his database name, username and password. The database is then created and I want those settings saved so that whenever the program runs it has the right database name, username and password to use. I would love it if they were saved in the program as opposed to an external file
Where will the database be stored?

As for the login credentials, you might as well save those to a separate file. There are ways to save the UI stack file itself, but with two trade-offs for doing so:

1. If you later update the UI in a future version you'll need to work out some way to get the data from the old stack before replacing it. For any app expected to live beyond one version, it's usually simpler to separate UI and data.

2. The data are login credentials, which should be stored encrypted on disk. There are clever ways to do this with stack files, but it's a lot of extra work.

Probably simpler to just package up the login data into a string, use the built-in encrypt command to encrypt the data, then write that to disk. When launching next time, read the data, use the decrypt command on it, then populate those three fields.

LiveCode's specialFolderPath function can be useful here. It accepts a variety of constants for different standard folders, such as specialFolderPath("Preferences"), which can then be appended with the name of the file you're using to store the data so your app can find it again next time it opens.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Save custom attributes in standalone

Post by dunbarx » Wed Jun 14, 2017 4:50 pm

dunbarx how do i save to a stack AFTER the program has been compiled to a standalone is the question
Do you mean you already have a standalone, and want to modify it to allow data to be saved? That is not possible if the standalone is the executable. You have to modify the original stack(s) oin the IDE and save anew.

Craig

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Save custom attributes in standalone

Post by Da_Elf » Wed Jun 14, 2017 5:33 pm

fourthworld the database is a mySQL database stored locally in its default installed folder

dunbarx exactly. Ive created the whole program and exported as a standalone. When i put it on a computer and run it for the first time it goes to a setup page which will ask for my user information for this particular instance. It will use this information to create a mySQL database based on these preferences. I want to be able to save the database info at this point. Then once the setup is done it enters the main part of the software and uses the info. Each time after the 1st running i would like it to skip the setup because it will see that data is there. It will go direct to the main part and use the preferences as before.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9838
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Save custom attributes in standalone

Post by FourthWorld » Wed Jun 14, 2017 5:56 pm

Did you mean SQLite? MySQL runs as a separate process, and unless your app is licensed under GPL there are licensing fees for distributing the MySQL dp package.

Either way, unless this is a one-off quickie app I think you'll find it easier over the long haul to just write that small login into to a small file in a default location.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Save custom attributes in standalone

Post by Da_Elf » Wed Jun 14, 2017 7:03 pm

fouthworld im using mysql community on a local machine. My software isnt designed to be on the market or anything (im not that good yet). Ive just created some apps for my friends to use which use a database and since im used to using mysql online with PHP i thought what the hell. ill just install locally. I did look in to mysql lite but there were some things it couldnt do that mysql could do (i cant remember what they are now). Its looking like i will just end up using an external file which i will encrypt the information so no one can read it.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”