The most obvious issue seems to be that you're not calling the function writeTimestamp
in your code. There are also a handful of other things that you might consider doing:
meSave()
.done(function () {
console.log('saved!');
});
function meSave() {
//create a var to store the the persisting data during the play
var dataSaved = {
/* put or fetch your game data here */
};
var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;
var filename = "dataFile.json";
return localFolder.createFileAsync(filename,
Windows.Storage.CreationCollisionOption.replaceExisting)
.then(function (file) {
return Windows.Storage.FileIO.writeTextAsync(file,
JSON.stringify(dataSaved));
}).then(function() {
// dataSaved.done ... although this would be lost if dataSaved is local
});
}
I changed a few things:
- There wasn't a need for an inner named function inside of the
meSave
function. I've replaced the function with anotherPromise
. In this way, your calling code can rely on thecallbacks
of thePromise
to be aware that the file has been saved to storage successfully. - You had extra variables (unused), and the
done
for the file creation was setting a variable that didn't exist locally (maybe it's somewhere else in your code).