Page 1 of 1
set/get preference file
Posted: Sun Jul 21, 2013 3:09 am
by maxs
I looked but could not find.
How can I make and get a preference file for IOS?
Re: set/get preference file
Posted: Sun Jul 21, 2013 4:10 pm
by Klaus
Hi Max,
the same way as on the desktop, maybe in another folder

Read from and write to -> specialfolderpath("documents") & "/your_pref_file_here"
Best
Klaus
Re: set/get preference file
Posted: Sun Jul 21, 2013 5:11 pm
by maxs
Thanks, Klaus,
So simple, but not so obvious for me.
Max
Re: set/get preference file not working
Posted: Sun Jul 21, 2013 5:55 pm
by maxs
It works for the Mac, but not ios.
I copied the special folder path folder with the file into the standalone prefs, but this code does nothing. Where did I go wrong?
on closecard
if the environment = mobile
then
open file specialfolderpath("myprefs") & "/PrefsMax"
write ( the number of this card ) to file "PrefsMax"
close file specialfolderpath("myprefs") & "/PrefsMax"
end if
end closecard
on opencard
global NewCardLoc
if the environment = mobile
then
if there is a file specialfolderpath("myprefs") & "/PrefsMax"
then
open file specialfolderpath("myprefs") & "/PrefsMax"
read from file "PrefsMax" at 1 until eof
put it into NewCardLoc
put it into fld "testit" of cd 2
close file specialfolderpath("myprefs") & "/PrefsMax"
end if
end if
end opencard
Re: set/get preference file
Posted: Sun Jul 21, 2013 5:59 pm
by Klaus
"myprefs" is NOT a valid "specialfolderpath", please check the dictionary if in doubt!
What's wrong with my proposal -> specialfolderpath("documents") ?
P.S.
You might want to use the shorter URL syntax:
...
put specialfolderpath("documents") & "/MinPrefs) into tPrefsFile
## Read:
put url("file:" & tPrefsFile) into fld "Wherever you want to display the prefs..."
...
## Write:
put the num of this cd into url("file:" & tPrefsFile)
...
Re: set/get preference file
Posted: Sun Jul 21, 2013 9:31 pm
by maxs
Thank you Klaus
I really like
put the num of this cd into url("file:" & tPrefsFile)
Does that save the number into a permanent file on the ipad? I can not be sure when using the simulator.
Max
Re: set/get preference file
Posted: Sun Jul 21, 2013 9:45 pm
by Klaus
Hi Max,
the simulator is also still a mistery to me
Yes, this will save to a "permanent" file on the device itself!
Best
Klaus
Re: set/get preference file
Posted: Sun Jul 21, 2013 9:52 pm
by Jellicle
I use these three scripts to manage preferences. For example, if I want to write the value "1" to line 3 of the preferences file I call:
setPref 3, "1"
To get the value in line 3 of the preferences file I call:
getPref (3)
The writefile script simply manages the writing of the preferences file to the device.
------------
on setPref whichPref, whatValue
open file specialFolderPath("Documents") & "/prefs.txt"
read from file specialFolderPath("Documents") & "/prefs.txt" until eof
close file specialFolderPath("Documents") & "/prefs.txt"
put whatValue into line whichPref of it
writeFile "prefs", it
end setPref
function getPref lineNumber
open file specialFolderPath("Documents") & "/prefs.txt"
read from file specialFolderPath("Documents") & "/prefs.txt" until eof
close file specialFolderPath("Documents") & "/prefs.txt"
return line lineNumber of it
end getPref
on writefile fileTowrite,dataTowrite
set the defaultFolder to specialFolderPath("Documents")
put dataTowrite into URL (("file:"&fileTowrite&".txt"))
end writefile
Cheers
Gerry