Custom Properties

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Custom Properties

Post by doobox » Sat Jun 25, 2011 7:54 pm

This still does not work properly.
I save as standalone for osx... and remove the previous saved file from preferences... run the app.
Runs as expected, first run... ( so the created stack is being called, and all is well)
Second run is a different story,. It does not show any data at all in the result field...?

!6 hours on this i have spent ;-( I am sure i will get there soon :-)

Here is the last code used:

Code: Select all

    local tFilePath
    
    on openStack
       put specialFolderPath("preferences") into tFilePath
       put tFilePath & "/myprefs.livecode" into tFilePath
       
       if not (there is a file tFilePath) then
          create stack tFilePath
          set the filename of stack tFilePath to tFilePath
          save stack tFilePath
          --hide newstack
       else
          go stack tFilePath
          --save  stack tFilePath
          --hide stack tFilePath
          --go this stack
       end if
       
       set the username of stack tFilePath to "user"
       set the settings of stack tFilePath to "1,2,3,4,5"
       
       wait 3 seconds
       put empty into field "result"
       wait 3 seconds
       put the username of stack tFilePath into field "result"
       wait 2 seconds
       put the settings of stack tFilePath after field "result"
    end openStack


    on shutdown
      save stack tFilePath
      pass shutdown
    end shutdown
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Custom Properties

Post by jacque » Sat Jun 25, 2011 10:39 pm

When you "go" to a stack, it becomes the default stack and all object references will refer to that stack unless you specify otherwise. If you don't have a field "result" on the prefs stack, the script will error. In a standalone, errors aren't shown unless you do something to catch them, so it looks like nothing happens.

Change your script in some way so that the main stack becomes the recipient. You can do this in lots of ways:

1. After going to prefs, go back to main before attempting to populate the fields.
2. Refer to the fields with a long descriptor: put the username of stack tFilePath into field "result" of stack "main"
3. Don't "go" to prefs at all, just get the data from it. Getting data from a closed stack will automatically open it, provided you refer to it with a file path, but won't make it the default stack. This is what I usually do. If you choose this method, you don't need an "else" in your openstack handler at all.

Code: Select all

on openStack
       put specialFolderPath("preferences") into tFilePath
       put tFilePath & "/myprefs.livecode" into tFilePath
       
       if not (there is a file tFilePath) then
          create stack tFilePath
          set the filename of stack tFilePath to tFilePath
          save stack tFilePath
          go stack "main" -- make it the defaultstack
       end if
       
       set the username of stack tFilePath to "user" -- referring to the stack using a file path opens it if the path is correct
       set the settings of stack tFilePath to "1,2,3,4,5"
       
       wait 3 seconds
       put empty into field "result"
       wait 3 seconds
       put the username of stack tFilePath into field "result"
       wait 2 seconds
       put the settings of stack tFilePath after field "result"
    end openStack
Add some error checking. After the first "set", get the result. If there's an error finding the stack or opening it, the result will contain the error and you can "answer" that or provide some other way to tell (put it in a log field, whatever.) In fact, it's a good idea to get the result after any operation that may fail, at least while debugging.

Another way to do the same thing is to use a "try" structure, but start with the result for now:

Code: Select all

set the username of stack tFilePath to "user" -- referring to the stack using a file path opens it
if the result is not empty then answer the result
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Custom Properties

Post by doobox » Sat Jun 25, 2011 11:05 pm

THX a million jacque,

I will put fresh eyes back on this in the morning, and let you know how i get on.
The penny is dropping in lots of areas though. build 106 is enough for the day :-)
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Custom Properties

Post by doobox » Sun Jun 26, 2011 12:42 am

Ah well i just could not put it down.

I have it working now thanks to you.
I changed tack slightly.
I am now saving the props into the prefs stack, from buttons on the masterStack.

And because of one remaining problem, i am re-saving the prefs stack just after the prop is set.
You will see the one problem commented in the bottom of the code.

I am pretty sure i can save the stack during run-time if i can not sort the on shutdown handler.
There is mention of an issue in the dictionary for shutdown, when used with other stacks,
but it did not really hit home what it is getting at.

Code: Select all

global tFilePath -- as i am using it elsewhere to save the stack

on preOpenStack -- swapped to pre open to stop a little flicker
   put specialFolderPath("preferences") into tFilePath
   put tFilePath & "/myprefs.livecode" into tFilePath
   
   if not (there is a file tFilePath) then
      create stack "thedata"
      put it into temp
      set the visible of temp to false
      set the filename of temp to tFilePath
      save temp
      go stack "MasterStack"
   end if
end preOpenStack -- works a treat, saving the prefs stack, just after props are stored from buttons etc.



-- this does not work though, i also tried the commented, no joy.
-- i can " save stack tFilePath " during normal runtime, but not in this handler.
on shutdown
   --open stack tFilePath
   save stack tFilePath
   --close stack tFilePath
end shutdown
Kind Regards
Gary

https://www.doobox.co.uk

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10044
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Custom Properties

Post by FourthWorld » Sun Jun 26, 2011 1:38 pm

Glad you got that working, Gary. With that under your belt you're about to have a very good time - being able to store any mix of textual and even binary data in custom properties makes using stack files for data storage a hard-to-beat option for robust, flexible storage.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Custom Properties

Post by doobox » Sun Jun 26, 2011 2:53 pm

Hi,

Your right there.!
I need to stop drifting off in the imagination of my new found possibility's and focus on the task in hand :-)

When i started this thread I was working on an iPhone app, and just drifted into testing on osx for the learning curve.
Now i am back to the app. I am remembering the splash and data stack example. Where the data stack resides in the engine folder and is then moved to the documents folder.

I have the ios release notes open in front of me here, in the specialFolderPath section.
Trying to decide the best place to store just three pieces of textual data, collected from the user.

What is the ios equivalent of the preferences folder..? "cache"...?
Kind Regards
Gary

https://www.doobox.co.uk

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Custom Properties

Post by jacque » Mon Jun 27, 2011 4:27 am

What is the ios equivalent of the preferences folder..? "cache"...?
Documents, usually. Cache is for temporary data. Documents is backed up by iTunes.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply