Hi proza,
please let me first give the advise to also read related threads here!
"newbie question; write to file, read from file?" already has much info about this topic!
I do not know what exactly is going wrong in your script but I suggest that you use another syntax to read and write things to file(s).
Using the "url" syntax**** is much more readable and much less to type, because with that syntay you do not have to "open" the file before reading/writing and "close" the files after you are finished. Rev will do that for you
***Check the docs for "URL"!
The basic syntax is for writing:
...
put "text or whatever goes here" into url("file:" & "path/to/file/here.txt")
..
for reading:
...
put url("file:" & "path/to/file/here.txt") into fld "your field here"
## or any variable...
...
As you see, this can be done with ONE line of code!
Another good idea is to collect ALL your data first (in a variable) and then write it to a file in ONE piece.
Your example would then look like this:
...
put specialFolderPath("Preferences") & "/test" into theFile
put the label of btn "btn1" into collected_data
put CR & the label of btn "btn2" after collected_data
put CR & the label of btn "btn3" after collected_data
### add more data to the variable if necessary...
put collected_data into url("file:" & thefile)
...
That's it.
Same for reading that file in:
...
put specialFolderPath("Preferences") & "/test" into theFile
put url("file:" & thefile) into saved_data
set the label of btn "btn1" to line 1 of saved_data
set the label of btn "btn2" to line 2 of saved_data
## etc... you get the picture
..
This is more readable and will reduce read and write actions to the harddisk.
If you have a LOT of data, this may also be a bit faster than accessing the data on disk every time you need a tiny bit of it.
You can also put something BEFORE or AFTER the file, just like you would put something BEFORE or AFTER a field or variable.
So again, no need to "open file xyz for append"
...
put "This should go to line 1 of the file on disk" & CR BEFORE url("file:" & thefile)
...
put CR & "This will be the last line of the file on disk." AFTER url("file:" & thefile)
...
I hope this will work for you.
Try to get accustomed to this syntax, I really love the simplicity of it
Best
Klaus