Importing text file to save as a custom property

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
bqsbarbqGAnC5Z
Posts: 77
Joined: Thu Dec 08, 2011 12:19 pm

Importing text file to save as a custom property

Post by bqsbarbqGAnC5Z » Fri Jan 25, 2013 1:21 am

Hello everyone,

I've been having some difficulty trying to save a custom property from a locally saved text file. I was looking around the runrev documentation and I basically want to recreate this effect shown in Step 4. http://lessons.runrev.com/s/lessons/m/4 ... -LiveCode-

Code: Select all

on preOpenStack
   loadFile
   put the cProperty of this stack into field "MyProperty"
end preOpenStack

on loadFile
   put(URL("file://mnt/sdcard/myproperty.txt")) into tPath
   if there is a file tPath then
      set the cMyPropertyof this stack to URL("file://mnt/sdcard/myproperty.txt")
   end if
end loadInGameMoney
I know that this URL works because I am able to successfully save the file to that location, but I just can't seem to load the values back in. Would anyone have any advice on how I can do this? Thank you!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Importing text file to save as a custom property

Post by sturgis » Fri Jan 25, 2013 1:30 am

if you use the URL keyword (put URL "file:path/to/file.txt") you are putting the contents of the file into tPath
Then when you check o see if there is a file it will fail because you're checking the contents of the file, not a path.

Also, "there is a file.." expects a regular old path. Don't use "file:" as part of it. file: and binfile: tell the engine how to handle the file when you are working with its contents.

To make this work, put the path into tpath
put "/mnt/sdcard/myproperty.txt" into tPath

then check for its existence
if there is a file tPath then set the cMyProperty of this stack to to URL ("file:" & tpath)

Also, though its probably a typo, you have "set the cMyPropertyof..." so change it to "the cMyProperty of"

Also don't believe you need a // (file://) when accessing the url. file:/path/to/file should be the way to go.

Post Reply