Saving User Preferences - and using them

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Saving User Preferences - and using them

Post by bjb007 » Tue Mar 11, 2008 10:53 pm

The "Getting Started" example
"Preferences pane-saving to a stack or text file"
in "Ten functional examples"
doesn't go into much detail about reading
the user preferences at startup.

Anyone know of any further info on
the subject?
Life is just a bowl of cherries.

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Wed Mar 12, 2008 3:44 pm

Here is an example of what I am using in a stack to read a txt at startup:

Code: Select all

on openStack
  if there is a file "C:/Documents and Settings/All Users/Application Data/CK/settings.txt" then
    put line 1 of url "file:C:/Documents and Settings/All Users/Application Data/CK/settings.txt" into fld "audURL" of stack "settings"
  else
    Answer information "Settings are at default"
  end if
end openStack
You can of course have multiple put statements using the text chunking that best fits how you saved to the file in the first place.

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Post by Andycal » Wed Mar 12, 2008 6:21 pm

Saving is a doddle too:

Code: Select all

put the value of fld "theSize" of stack "Image" into line 1 of URL "file:preferences.txt"


bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Saving User Preferences - and using them

Post by bjb007 » Wed Mar 12, 2008 11:36 pm

I was thinking more along the lines
of reading from a text file into a
variable.

I expect it's possible. As I get annoyed
by programmes which give a message like
"New settings will take effect when you
restart" I wanted to perhaps read the
settings each time they're used so that
changes take effect immediately.

Or perhaps in the case of a number of
settings read them into an array and
access them from there.

Did think of checking the date/time of the
settings file each time but that's probably
no more efficient that reading the vars.
each time they're used (which would
be quite often).

Could also set a true/false when used
changes a setting.....

Lots of possibilities. My question came
from feeling that it seemed too easy!
Life is just a bowl of cherries.

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Thu Mar 13, 2008 3:52 am

So use a variable instead of a Field as in our examples. Probably just extra code though as fields make great containers and you need them anyway for settings changes.

As far as when to trigger this, you really only need to do it on stack open and stack close. As the settings changes user makes during runtime can be active right away.

Your description of doing this by checking the time is easy to do, but personally sounds over engineered. If you want to have it saved to the txt right away, I would just trigger it on change of the setting, clean and simple.

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Saving User Preferences - and using them

Post by bjb007 » Thu Mar 13, 2008 4:36 am

Right, keyless.

On giving the matter further thought I
did come to the conclusion that new
settings would be used during the
current session and could then
be saved at close.

Thanks for your input.
Life is just a bowl of cherries.

Post Reply