Read/Write/Restore Data
Posted: Sun Jun 10, 2012 11:18 pm
I am having difficulty saving user progress with an iOS app.There are 14 substest that can be administered. I have two fields set up to save the subtest data / progress. I am saving to these fields as the user progresses, and then writing them to a text file. The problem seems to be on shutdown and startup. The text files are not always written. Also, even if they are the answer handler on start up isn't working. This is what I have so far:
on openStack - This is in the 1st card script to make sure it gets called. No other openStack handlers in the project.
if the environment is "mobile" then play specialFolderPath("engine") & "/audio/iossoundprep.mp3" --establish the path to eliminate any delays.
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:geniepreferences.txt") into field "prefsField" of card "prefsCard" --User data file.
put URL ("file:markedcards.txt") into field "markedCardsField" of card "prefsCard" --List of the marked cards.
if card field "prefsField" of card "prefsCard" is not empty then answer "Continue Session?" with "Yes" or "No" --Not working.
if it is "Yes" then
restoreAllData --repopulate the data.
markTheCards --get's the saved list of marked cards and marks them.
put item 1 of line 58 of field "prefsField" of card "prefsCard" into tCurrentCard --name of the card the user exited on.
go to card tCurrentCard
else
send "clearData" to card "Data Card" in 20 --New session, clear all prior data.
put empty into card field "prefsField" of card "prefsCard" --Clear previous saved data.
put empty into card field "markedCardsField" of card "prefsCard" ----Clear previous saved data.
set the uText of control "Client Name Field" of card "PreferencesStartCard" to empty --MobGui text control.
put empty into card field "Name Field" of card "Data Card"
clearPictureDescr --Clears more data.
end if
end openStack
on shutdown - In the stack script; Have also tried closeStack.
global gCorrectAnswer, gAnswerCount, gcurrentPercentage, gFirstBtn, gLastBtn
put field "MLUfield" of card "Data Card" into item 1 of line 49 of field "prefsField" of card "prefsCard" -- data that can't be saved as the user progresses.
put gCorrectAnswer into item 1 of line 52 of field "prefsField" of card "prefsCard"
put gAnswerCount into item 1 of line 53 of field "prefsField" of card "prefsCard"
put gcurrentPercentage into item 1 of line 54 of field "prefsField" of card "prefsCard"
put gFirstBtn into item 1 of line 55 of field "prefsField" of card "prefsCard"
put gLastBtn into item 1 of line 56 of field "prefsField" of card "prefsCard"
put this card into item 1 of line 58 of field "prefsField" of card "prefsCard" --Save the current card so the user can resume if selected.
set the defaultFolder to specialFolderPath("Documents")
put field "prefsField" of card "prefsCard" into URL ("file:geniepreferences.txt") --Save the preferences / progress.
put field "markedCardsField" of card "prefsCard" into URL ("file:markedcards.txt") --Save the marked cards list.
end shutdown
This will be administered to special needs kids, so I need to be able to restore the session if they "accidentally" hit the home button. These kids are pretty smart with all things iPad. I will be glad to post additional scripts if it will be useful.
Thanks for you help!
on openStack - This is in the 1st card script to make sure it gets called. No other openStack handlers in the project.
if the environment is "mobile" then play specialFolderPath("engine") & "/audio/iossoundprep.mp3" --establish the path to eliminate any delays.
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:geniepreferences.txt") into field "prefsField" of card "prefsCard" --User data file.
put URL ("file:markedcards.txt") into field "markedCardsField" of card "prefsCard" --List of the marked cards.
if card field "prefsField" of card "prefsCard" is not empty then answer "Continue Session?" with "Yes" or "No" --Not working.
if it is "Yes" then
restoreAllData --repopulate the data.
markTheCards --get's the saved list of marked cards and marks them.
put item 1 of line 58 of field "prefsField" of card "prefsCard" into tCurrentCard --name of the card the user exited on.
go to card tCurrentCard
else
send "clearData" to card "Data Card" in 20 --New session, clear all prior data.
put empty into card field "prefsField" of card "prefsCard" --Clear previous saved data.
put empty into card field "markedCardsField" of card "prefsCard" ----Clear previous saved data.
set the uText of control "Client Name Field" of card "PreferencesStartCard" to empty --MobGui text control.
put empty into card field "Name Field" of card "Data Card"
clearPictureDescr --Clears more data.
end if
end openStack
on shutdown - In the stack script; Have also tried closeStack.
global gCorrectAnswer, gAnswerCount, gcurrentPercentage, gFirstBtn, gLastBtn
put field "MLUfield" of card "Data Card" into item 1 of line 49 of field "prefsField" of card "prefsCard" -- data that can't be saved as the user progresses.
put gCorrectAnswer into item 1 of line 52 of field "prefsField" of card "prefsCard"
put gAnswerCount into item 1 of line 53 of field "prefsField" of card "prefsCard"
put gcurrentPercentage into item 1 of line 54 of field "prefsField" of card "prefsCard"
put gFirstBtn into item 1 of line 55 of field "prefsField" of card "prefsCard"
put gLastBtn into item 1 of line 56 of field "prefsField" of card "prefsCard"
put this card into item 1 of line 58 of field "prefsField" of card "prefsCard" --Save the current card so the user can resume if selected.
set the defaultFolder to specialFolderPath("Documents")
put field "prefsField" of card "prefsCard" into URL ("file:geniepreferences.txt") --Save the preferences / progress.
put field "markedCardsField" of card "prefsCard" into URL ("file:markedcards.txt") --Save the marked cards list.
end shutdown
This will be administered to special needs kids, so I need to be able to restore the session if they "accidentally" hit the home button. These kids are pretty smart with all things iPad. I will be glad to post additional scripts if it will be useful.
Thanks for you help!