Writing a Windows 8 app in Javascript using Visual Studio Express. I’m not sure if I am missing a chaining dependency or something else, but I am giving my game users the ability to save their progress into a file (at least that’s the idea). However when I run the following code it appears that even though I can see the file out there, the file pointer is turning out to be undefined. See anything I’m missing?
var myStats = new Array();
myStats[0] = myTitle;
myStats[1] = currPage;
myStats[2] = currStep;
myStats[3] = currTune;
myStats[4] = musicon;
myStats[5] = gameComplete;
var save01File = null;
Windows.Storage.KnownFolders.documentsLibrary.createFileAsync("Asave01.dat", Windows.Storage.CreationCollisionOption.replaceExisting).done(
function (file) {
save01File = file;
},
function (error) {
WinJS.log && WinJS.log(error, "sample", "error");
});
Windows.Storage.FileIO.writeLinesAsync(save01File, myStats).done(
function () {
},
function (error) {
WinJS.log && WinJS.log(error, "sample", "error");
errCount++;
});
if (errCount == 0) {
fileMenuTitle.text = "File Saved - Click Cancel";
fileMenuTitle.text = fileMenuTitle.text + "\nto Return or Select Another File to Load";
fileMenuTitle.color = "green";
}
else {
fileMenuTitle.text = "There was an error saving that file.";
fileMenuTitle.text = fileMenuTitle.text + "\nPlease Make Another Selection.";
fileMenuTitle.color = "firebrick";
}
You need to use the promise pattern here: