A little confusion about save stack

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Apr 16, 2009 8:30 pm

forgive me, but this is a bit hard to explain, and thank you for your patience and help. I think the problem is the complexity of my array. It is set up as tMainArray[documentnumber][linknumber][miscData] (documentnumber and link number are literal numbers in the keys miscdata is several word named keys) besides having the numbered keys at each level there are also some named keys that tell me about the contents of the numbered elements and about the parent element. eg tMainArray[1][nooflinks] holds the total number of how many numbered child elements there are in tMainArray[1] and tMainArray[1][docname] holds the name of the document that tMainArray[1] represents. When I save the array and reload it, I can retrieve the data from tMainArray[x][x], but the data in the third level of elements is gone.

e.g if tMainArray[3][2][coords] = 122,12,129,65
and tMainArray[3][nooflinks] = 7

after saving and loading

tMainArray[3][nooflinks] will still be 7 however, tMainArray[3][2][coords] will be empty.

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

Post by sturgis » Thu Apr 16, 2009 9:14 pm

Hmm Interesting. I just tried the following code:

Code: Select all

on mouseUp
   put "122,12,129,65" into myA[1][1][coords]
   set customProperties["myAProps"] of this stack to myA
   put customProperties["myAProps"] of this stack into testA
   put testA[1][1][coords]
end mouseUp
This worked as expected. Its much simplified of course, but is putting the correct information into the message box, so I have a couple questions for you.

Is coords used elsewhere, so maybe its seeing it as a variable? If thats the case, using quotes as mentioned earlier will help with that issue.

I assume you've built the array, and checked the values before and after setting and recapturing the array from the properties, and you can pop the information out before not after right? Thats why I used 2 diff array names so that I can check whats was put in vs what was returned.

How are you putting the coords into the array? Is it possible they're going in as keys and not values?

You can test this theory to eliminate it by putting

Code: Select all

answer the keys of testA[3][2][coords]
into your code. If it returns 122 12 129 65 that tells you something right there. If not, you can eliminate that as a possibility.

magice wrote:forgive me, but this is a bit hard to explain, and thank you for your patience and help. I think the problem is the complexity of my array. It is set up as tMainArray[documentnumber][linknumber][miscData] (documentnumber and link number are literal numbers in the keys miscdata is several word named keys) besides having the numbered keys at each level there are also some named keys that tell me about the contents of the numbered elements and about the parent element. eg tMainArray[1][nooflinks] holds the total number of how many numbered child elements there are in tMainArray[1] and tMainArray[1][docname] holds the name of the document that tMainArray[1] represents. When I save the array and reload it, I can retrieve the data from tMainArray[x][x], but the data in the third level of elements is gone.

e.g if tMainArray[3][2][coords] = 122,12,129,65
and tMainArray[3][nooflinks] = 7

after saving and loading

tMainArray[3][nooflinks] will still be 7 however, tMainArray[3][2][coords] will be empty.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Apr 16, 2009 10:05 pm

I did a test like yours before I implemented in my app. In my test it seemed to work fine. The array is exactly as it should be, because the app works. It uses the array to generate linked image map html documents. Exporting to html works like a charm so I know the array is properly filled. However after saving and loading it does not. I wonder if it could have something to do with having keys that have no value. There are situations where, if the end user picks a document to edit and then changes his mind there will be a key that has an empty value. Could that be gumming up the works? Maybe the save process doesn't know how to handle these empty keys, and so it puts the next key in the value slot of the last key instead of leaving it empty? That could explain some eratic behavior i have observed.

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

Post by sturgis » Thu Apr 16, 2009 10:21 pm

Hmm, not sure at this point. Since you did a test like mine and it worked it does seem like we're missing something.

If what you're asking is what is actually happening, it makes me wonder if some of the keys ever get created when you restore from the custom property. IE does

Code: Select all

answer the keys of tMainArray[3][2] 
return coords (from your example) as one of the keys, whether its empty or not?

I have a suspicion that you'll keep beating your head against this wall then have an Ah HAH moment, but things are getting complicated enough now its hard to know how to help without you posting lots of code. :lol:

I'll keep thinking on it and try to reproduce the problem locally here. If you find the answer let me know if you would?

Thanks

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Apr 17, 2009 6:36 am

OK I think I figured it out. The arrays are saving ok. They are not loading.

this is my script for loading:

Code: Select all

 
   global tMainArray
   global tMainArrayInc
   global tSubInc
   global tFieldDataArray
   global myClick
   global tVarSave
   
   
   put the customProperties["varSave"] of this stack into tVarSave
   if tVarSave[5] = true
   then
      put the customProperties["mainArray"] of this stack into tMainArray 
      put the customProperties["fieldDataArray"] of this stack into tfieldDataArray 
      put the customProperties["varSave"] of this stack into tVarSave
      
      put tVarSave[1] into tMainArrayInc  
      put  tVarSave[2] into tSubInc
      put tVarSave[3] into tRectInc  
      put tVarSave[4] into myClick  
      
   end if
I can put that in a button and manually load the arrays and every thing works fine. However I was trying to put it in my openCard script so it would run at start up. With a little testing I have determined that this script must be running before the custom properties load. How would be a good way to auto initiate it when the stack loads?

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Apr 17, 2009 5:50 pm

Problem resolved, and just in case anyone else reads this and is trying to resolve the same issue this is what I did. Since the script worked from a button and not from the openCard command, I created a standard End User License Agreement stack that shows up on openCard. The agree button runs the script.

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

Post by sturgis » Fri Apr 17, 2009 6:20 pm

Thanks for the info. I had another though on how to make it run too if you're interested.

If you put your script for loading into a command say..

Code: Select all

command loadItUp
and then in openCard put

Code: Select all

send "loadItUp" to me in 0 seconds
Does that work?
magice wrote:Problem resolved, and just in case anyone else reads this and is trying to resolve the same issue this is what I did. Since the script worked from a button and not from the openCard command, I created a standard End User License Agreement stack that shows up on openCard. The agree button runs the script.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Apr 17, 2009 7:18 pm

Yeah I tried that first....It didn't work. Apparantly you have to let the entire program load up before the script can be run.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Sat Apr 18, 2009 12:55 am

post deleted to put in new thread

Post Reply