Problem Saving and Loading Data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Problem Saving and Loading Data
I've got another LiveCode file that's been saving and loading data in the development environment and as a stand-alone for over a decade, and it seems like I'm doing the same thing with this new problem stack, but I can't get it to work. My goal is to get changes to the field "NotesField" of the card "NotesCard" of the mainstack "SchoolMAX Clipboard" to persist when the stack is closed and reopened. I'm saving the data to and loading it from field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode".
Here's the simple script of the mainstack--and darn near the only script in the whole stack:
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
I don't know if that "go invisible" line is necessary at all. It's just one of the things I've tried in my troubleshooting.
The place I intend my data be saved, the stack "SchoolMAX Clipboard Data.livecode", is listed with its correct relative path (relative to mainstack SchoolMAX Clipboard") in the "Copy Files" tab of the "Standalone Application Settings" window and not listed at all in the "Stacks" tab.
The weird thing is I don't even know that this is a standalone stack problem because of the third point below:
--The loading and saving of data does not work in standalone form.
--The loading and saving of data does work in the development environment IF I close the stack by clicking its window's close button.
--The loading and saving of data does not work in the development environment if I simply quit LiveCode.
I've put in all sorts of "answer" statements (they're not there now) to ensure that, in both the developer environment and standalone mode:
--The defaultFolder is correctly set to the folder that contains "SchoolMAX Clipboard Data.livecode".
--The saveData and loadData handlers are firing when the stack opens and when it closes.
I know the saveData and loadData handlers work, too, because I've test fired them from the Message Box. If I make a change to field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" then fire the saveData handler from the Message Box, the change is transferred to field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode". Transferring a change the opposite way works if I fire the loadData handler in the Message Box.
This is driving me nuts. It seems so simple, but I must be doing something fundamentally wrong. It seems like I should get an error message, but I don't. Help?
Here's the simple script of the mainstack--and darn near the only script in the whole stack:
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
I don't know if that "go invisible" line is necessary at all. It's just one of the things I've tried in my troubleshooting.
The place I intend my data be saved, the stack "SchoolMAX Clipboard Data.livecode", is listed with its correct relative path (relative to mainstack SchoolMAX Clipboard") in the "Copy Files" tab of the "Standalone Application Settings" window and not listed at all in the "Stacks" tab.
The weird thing is I don't even know that this is a standalone stack problem because of the third point below:
--The loading and saving of data does not work in standalone form.
--The loading and saving of data does work in the development environment IF I close the stack by clicking its window's close button.
--The loading and saving of data does not work in the development environment if I simply quit LiveCode.
I've put in all sorts of "answer" statements (they're not there now) to ensure that, in both the developer environment and standalone mode:
--The defaultFolder is correctly set to the folder that contains "SchoolMAX Clipboard Data.livecode".
--The saveData and loadData handlers are firing when the stack opens and when it closes.
I know the saveData and loadData handlers work, too, because I've test fired them from the Message Box. If I make a change to field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" then fire the saveData handler from the Message Box, the change is transferred to field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode". Transferring a change the opposite way works if I fire the loadData handler in the Message Box.
This is driving me nuts. It seems so simple, but I must be doing something fundamentally wrong. It seems like I should get an error message, but I don't. Help?
Re: Problem Saving and Loading Data
Due to the fact that the stack file format has changed a couple of times over the past years, I no longer try to save *anything* in stacks, but create text files and save the data there. That way I'm immune to any LiveCode changes.
BTW - your stack "SchoolMAX Clipboard Data.livecode" is a separate file and not a substack of your mainstack, right? It looks like you're attempting to load a separate file, but the comment about setting the mainstack confuses me.
And you might try saving your data on closeStackRequest instead of closeStack to see if that helps.
BTW - your stack "SchoolMAX Clipboard Data.livecode" is a separate file and not a substack of your mainstack, right? It looks like you're attempting to load a separate file, but the comment about setting the mainstack confuses me.
And you might try saving your data on closeStackRequest instead of closeStack to see if that helps.
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Re: Problem Saving and Loading Data
Thanks for the suggestions, mwieder. The comment about setting the mainstack of the separate file to itself: If its mainstack is set to the main application stack, then it's a substack of it, right? So I set the separate file's mainstack to itself--so it's not a substack. That works in the other application that's been doing fine for a good decade, anyway. I really don't understand, obviously, the complete truth about saving data in a separate stack. It's not explained clearly anywhere that I've found.
Re: Problem Saving and Loading Data
Well, not exactly. If you're doing this at runtime in a standalone app, all you're doing is having two separate mainstacks in memory at the same time. No problem with doing that, you can have any number of stacks hovering about in memory as long as they don't have the same names.So I set the separate file's mainstack to itself--so it's not a substack.
But... in order to save information in a stack it has to be a separate stack *file* on the disk. And just setting the mainstack doesn't change that. You have to save the stack onto the disk explicitly, otherwise it doesn't have a filename.
If you separate your data stack from your mainstack at development time and make it a separate file then you can get away with what you want to do, but then you have to take care of loading your data stack into memory and saving it when you're done.
Saving data into a standalone app's file is prohibited by all operating systems - it's not a LiveCode limitation, but an OS restriction. The only OS that allowed this is pre-OSX Mac OS versions.
-
- Livecode Opensource Backer
- Posts: 107
- Joined: Fri Nov 10, 2006 8:58 pm
- Contact:
Re: Problem Saving and Loading Data
I added an "answer" in three places below...
--------
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
Then I saved as a standalone.
I opened the standalone and dismissed the first answer dialog since it wouldn't tell me anything yet.
I changed something in the field "NotesField" then closed the standalone.
On closing, the first answer dialog didn't show the change and the second answer dialog did, which is what should happen.
I reopened the standalone, and the answer dialog didn't show the change.
Conclusion: Everything is working as I intend except that changes to the data stack, while they can be made, can't be saved. My data stack, even though it's a .livecode file in the standalone build, doesn't save changes to itself when it closes. I don't have to explicitly tell it to save itself, do I? I've never done that with my other, working project*. It seems my data stack somehow has the "can't save changes to itself" stigma of a .app or .exe. Ideas?
I tried your closeStackRequest suggestion, mwieder, but it made no difference. I wouldn't expect it to if my conclusion in the previous paragraph is correct.
*Liar, liar, pants on fire! I did TOO explicitly SAVE my data stacks in my other, working project, but I overlooked that detail when looking back over the ancient script. Sorry, everybody. It appears that's the simple solution.
--------
on preOpenStack
set the blendLevel of me to 10
local itemDelimParking
local ldefaultFolder
put the fileName of me into ldefaultFolder
put the itemDelimiter into itemDelimParking
set the itemDelimiter to "/"
put "" into the last item of ldefaultFolder
put "Data" after ldefaultFolder
set the defaultFolder to ldefaultFolder
set the itemDelimiter to itemDelimParking
set the menuhistory of button "Tabs" to 1
go invisible card "NotesCard" of stack "SchoolMAX Clipboard Data.livecode" -- Must set the mainStack of this stack to itself in Property Inspector.
loadData
end preOpenStack
on remoteMouseUp -- Called by each colored button, example button "0100 GRADE PK".
set the clipboardData["text"] to the short name of the target
end remoteMouseUp
on closeStack
saveData
close stack "SchoolMAX Clipboard Data.livecode"
end closeStack
on loadData
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
put field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode" into field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard"
end loadData
on saveData
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
put field "NotesField" of card "NotesCard" of stack "SchoolMAX Clipboard" into field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
answer field "DataNotesField" of card "DataNotesCard" of stack "SchoolMAX Clipboard Data.livecode"
end saveData
------
Then I saved as a standalone.
I opened the standalone and dismissed the first answer dialog since it wouldn't tell me anything yet.
I changed something in the field "NotesField" then closed the standalone.
On closing, the first answer dialog didn't show the change and the second answer dialog did, which is what should happen.
I reopened the standalone, and the answer dialog didn't show the change.
Conclusion: Everything is working as I intend except that changes to the data stack, while they can be made, can't be saved. My data stack, even though it's a .livecode file in the standalone build, doesn't save changes to itself when it closes. I don't have to explicitly tell it to save itself, do I? I've never done that with my other, working project*. It seems my data stack somehow has the "can't save changes to itself" stigma of a .app or .exe. Ideas?
I tried your closeStackRequest suggestion, mwieder, but it made no difference. I wouldn't expect it to if my conclusion in the previous paragraph is correct.
*Liar, liar, pants on fire! I did TOO explicitly SAVE my data stacks in my other, working project, but I overlooked that detail when looking back over the ancient script. Sorry, everybody. It appears that's the simple solution.
Re: Problem Saving and Loading Data
*
Whew! Because I'm otherwise out of ideas.

Whew! Because I'm otherwise out of ideas.