Page 2 of 2
Re: Save variables after closing the app
Posted: Wed Jul 01, 2020 9:55 pm
by SparkOut
Klaus wrote: Wed Jul 01, 2020 9:38 pmThat lesson, like a lot more, needs to be updated to make sense and to reflect the value of the "new" specialfolderpath("resources")!
urgh... I thought it HAD been updated, but didn't study it.
There's also this lesson which is nominally for mobile but applies some of the required techniques
http://lessons.livecode.com/m/4069/l/15 ... ile-device
Re: Save variables after closing the app
Posted: Wed Jul 01, 2020 9:59 pm
by Klaus
Ooops, might also fail on iOS because -> specialFolderPath("
Documents")
needs to be -> set the defaultFolder to specialFolderPath("
documents")
Note the small caps
d of documents!

Re: Save variables after closing the app
Posted: Wed Jul 01, 2020 10:13 pm
by SparkOut
ugh, Android too actually

Re: Save variables after closing the app
Posted: Wed Jul 01, 2020 10:36 pm
by Klaus
SparkOut wrote: Wed Jul 01, 2020 10:13 pmugh, Android too actually

Ouch!
Will inform the mothership tomorrow!
Re: Save variables after closing the app
Posted: Thu Jul 02, 2020 9:14 am
by richmond62
"Unfortunately" while most things (c.f. numToChar versus numToCodePoint) remain the same in LiveCode
they don't seem to in the world of operating systems and file systems.
Therefore any lessons offered online that interact with anything outwith LiveCode itself need to be
constantly watched, tested against new versions of systems, and updated where necessary.
Re: Save variables after closing the app
Posted: Thu Jul 09, 2020 11:15 am
by AGC studios
hi, this code isnt working, any ideas? (Android)
Code: Select all
on openStack
set the defaultFolder to specialFolderPath("documents")
put URL ("file:test.txt") into tSec
put tSec into field "fsField"
end openStack
on shutdown
set the defaultFolder to specialFolderPath("documents")
put "second" into URL ("file:test.txt")
pass shutdown
end shutdown
tSec is empty so I would have guessed test.txt is empty or not even created...
i also tried using a caps "D" in documents
tnx
Re: Save variables after closing the app
Posted: Thu Jul 09, 2020 11:48 am
by Klaus
You really should start with some error checking!
1. Check if file is really present:
Code: Select all
on openStack
put specialFolderPath("documents") & "/test.txt" into tFile
IF THERE IS A FILE TFILE then
put URL ("file:" & tFile") into tSec
ELSE
put "No file yet!" into tSec
end if
put tSec into field "fsField"
end openStack
2. Check if writing was successfull:
Code: Select all
on shutdown
put specialFolderPath("documents") & "/test.txt" into tFile
put "second" into URL ("file:" & tFile)
if the result <> EMPTY then
answer "Error writing file!" & CR & the result & CR & syserror()
end if
pass shutdown
end shutdown
Maybe the answer dialog will show what might have gone wrong.
P.S.
As you can see I am not a friend of "messin' with the defaultfolder".
If I can have an absolute pathname, I will use it!
Re: Save variables after closing the app
Posted: Thu Jul 09, 2020 12:36 pm
by mrcoollion
Maybe this is what you can use?
See the Demo Stack I attached at the following topic.
viewtopic.php?f=12&t=33338
viewtopic.php?f=12&t=33338#p185397
Regards,
Paul
Re: Save variables after closing the app
Posted: Thu Jul 09, 2020 6:50 pm
by FourthWorld
AGC studios wrote: Thu Jul 09, 2020 11:15 am
hi, this code isnt working, any ideas? (Android)
"Isn't working" is hard to fix.
With any file I/O it's very useful to check the result immediately after the I/O statement, and if not empty then query sysError() to find out the specific error code the OS is passing to LC about why it failed.
Re: Save variables after closing the app
Posted: Fri Jul 10, 2020 3:01 pm
by AGC studios
Thanks, the problem was with the shutdown handler, so I changed it.