{"id":998,"date":"2022-08-30T15:10:41","date_gmt":"2022-08-30T15:10:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/file-pointer-from-createfileasync-in-windows-8-javascript-is-undefined-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:10:41","modified_gmt":"2022-08-30T15:10:41","slug":"file-pointer-from-createfileasync-in-windows-8-javascript-is-undefined-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/file-pointer-from-createfileasync-in-windows-8-javascript-is-undefined-collection-of-common-programming-errors\/","title":{"rendered":"File Pointer from CreateFileAsync in Windows 8 Javascript is undefined-Collection of common programming errors"},"content":{"rendered":"<p>Writing a Windows 8 app in Javascript using Visual Studio Express. I&#8217;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&#8217;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&#8217;m missing?<\/p>\n<pre><code>var myStats = new Array();\nmyStats[0] = myTitle;\nmyStats[1] = currPage;\nmyStats[2] = currStep;\nmyStats[3] = currTune;\nmyStats[4] = musicon;\nmyStats[5] = gameComplete;\n\nvar save01File = null;\n\n            Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(\"Asave01.dat\", Windows.Storage.CreationCollisionOption.replaceExisting).done(\n\n                function (file) {\n                    save01File = file;\n                },\n                function (error) {\n                    WinJS.log &amp;&amp; WinJS.log(error, \"sample\", \"error\");\n                });\n            Windows.Storage.FileIO.writeLinesAsync(save01File, myStats).done(\n                function () {\n                },\n            function (error) {\n                WinJS.log &amp;&amp; WinJS.log(error, \"sample\", \"error\");\n                errCount++;\n            });\n            if (errCount == 0) {\n                fileMenuTitle.text = \"File Saved - Click Cancel\";\n                fileMenuTitle.text = fileMenuTitle.text + \"\\nto Return or Select Another File to Load\";\n                fileMenuTitle.color = \"green\";\n            }\n            else {\n                fileMenuTitle.text = \"There was an error saving that file.\";\n                fileMenuTitle.text = fileMenuTitle.text + \"\\nPlease Make Another Selection.\";\n                fileMenuTitle.color = \"firebrick\";\n            }\n<\/code><\/pre>\n<ol>\n<li>\n<p>You need to use the promise pattern here:<\/p>\n<pre><code>var myStats = new Array();\nmyStats[0] = myTitle;\nmyStats[1] = currPage;\nmyStats[2] = currStep;\nmyStats[3] = currTune;\nmyStats[4] = musicon;\nmyStats[5] = gameComplete;\n\nvar save01File = null;\n\nWindows.Storage.KnownFolders.documentsLibrary.createFileAsync(\"Asave01.dat\", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {\n    save01File = file;\n    return Windows.Storage.FileIO.writeLinesAsync(file, myStats);\n}).done(function() {\n    fileMenuTitle.text = \"File Saved - Click Cancel\";\n    fileMenuTitle.text = fileMenuTitle.text + \"\\nto Return or Select Another File to Load\";\n    fileMenuTitle.color = \"green\";\n}, function (error) {\n    WinJS.log &amp;&amp; WinJS.log(error, \"sample\", \"error\");\n    fileMenuTitle.text = \"There was an error saving that file.\";\n    fileMenuTitle.text = fileMenuTitle.text + \"\\nPlease Make Another Selection.\";\n    fileMenuTitle.color = \"firebrick\";\n});\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:12:03. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Writing a Windows 8 app in Javascript using Visual Studio Express. I&#8217;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&#8217;s the idea). However when I run the following code it appears that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-998","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=998"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/998\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}