Saving data

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Saving data

Post by ferhan24badshah » Sun Mar 02, 2014 3:34 am

So I'm almost done with my app for an android platform. My app basically stores data day by day according to what the user inputs in the app. I just came to realize that when the phone is restarted, turned off, or the app is cleared from active apps.....all the data stored on the app is gone!! :/ Is there anyway to prevent this from happening?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving data

Post by Simon » Sun Mar 02, 2014 4:00 am

Hi Ferhan,
Nope :)

You have to store the data somewhere;

Code: Select all

on mouseUp
   put specialFolderPath("documents") & "/Data.dat" into tFile
   if there is a file tFile then
      put url ("file:" & tFile) into tData
      answer tData --show the contents of the file
   else
      answer "No data file located" --First run
   end if
end mouseUp
and reload it on startup.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: Saving data

Post by ferhan24badshah » Sun Mar 02, 2014 4:05 am

Simon wrote:Hi Ferhan,
Nope :)

You have to store the data somewhere;

Code: Select all

on mouseUp
   put specialFolderPath("documents") & "/Data.dat" into tFile
   if there is a file tFile then
      put url ("file:" & tFile) into tData
      answer tData --show the contents of the file
   else
      answer "No data file located" --First run
   end if
end mouseUp
and reload it on startup.

Simon

Hey Simon,

yeah i figured....was hoping for a miracle haha..

hmm is it okay if you clarify the code you have written? I'm not too sure what's going on...what button is being pressed? and the content is a bit confusing...not quite sure what is happening. thank you

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving data

Post by Simon » Sun Mar 02, 2014 4:15 am

OK here it goes
put specialFolderPath("documents") & "/Data.dat" into tFile
This is where the files are stored on mobile, Data.dat is just a filename
if there is a file tFile then
put url ("file:" & tFile) into tData

Go get the file if it is there.

So you have a game with a high score
each time you score a point you add it to tData
Normally I'd say when you close the app write tData out to a file but for mobile I say just write it every time a score is made.
put tData into url("file:" & tFile) (tFile may be a global)

Do you see how it works now?

Simon
Edit oh... yes you'd look for the file on openCard or somewhere
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply