Save variables after closing the app

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Re: Save variables after closing the app

Post by SparkOut » Wed Jul 01, 2020 9:55 pm

Klaus wrote:
Wed Jul 01, 2020 9:38 pm
That 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

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

Re: Save variables after closing the app

Post by Klaus » Wed Jul 01, 2020 9:59 pm

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! :D

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

Re: Save variables after closing the app

Post by SparkOut » Wed Jul 01, 2020 10:13 pm

ugh, Android too actually :roll:

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

Re: Save variables after closing the app

Post by Klaus » Wed Jul 01, 2020 10:36 pm

SparkOut wrote:
Wed Jul 01, 2020 10:13 pm
ugh, Android too actually :roll:
Ouch! :shock:

Will inform the mothership tomorrow!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9378
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Save variables after closing the app

Post by richmond62 » Thu Jul 02, 2020 9:14 am

"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.

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Save variables after closing the app

Post by AGC studios » Thu Jul 09, 2020 11:15 am

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

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

Re: Save variables after closing the app

Post by Klaus » Thu Jul 09, 2020 11:48 am

You really should start with some error checking! :D

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". 8)
If I can have an absolute pathname, I will use it!

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Save variables after closing the app

Post by mrcoollion » Thu Jul 09, 2020 12:36 pm

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

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

Re: Save variables after closing the app

Post by FourthWorld » Thu Jul 09, 2020 6:50 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Save variables after closing the app

Post by AGC studios » Fri Jul 10, 2020 3:01 pm

Thanks, the problem was with the shutdown handler, so I changed it.

Post Reply

Return to “Talking LiveCode”