{"id":21611,"date":"2013-11-20T09:37:57","date_gmt":"2013-11-20T14:37:57","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21611"},"modified":"2015-07-01T04:49:26","modified_gmt":"2015-07-01T09:49:26","slug":"good-robot-29-saves-go-in-the-save-place","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21611","title":{"rendered":"Good Robot #29: Saves Go In the Save Place"},"content":{"rendered":"<p>Players expect to be able to save their game. Which creates the question of, &#8220;Where do we store those saves?&#8221; Previously we&#8217;ve seen some surprisingly lively debates around the subject in the comments.  I can&#8217;t find it now, but one person even went so far as to say that if a game doesn&#8217;t save in the \/My Documents\/ folder then the game is broken.<\/p>\n<p>I can understand this. Microsoft created the \/My Documents\/ folder as a place for applications to store their crap. In an ideal world, someone wanting to back up their computer ought to be able to back up \/My Documents\/ and be reasonably certain they have everything. It&#8217;s supposed to be a general dumping ground for text documents, spreadsheets, game saves, configuration settings, power point presentations, email archives, web bookmarks, drawings, photographs, and whatever other data people create with their computers. It&#8217;s one location where users should be able to look and find ALL their files.<\/p>\n<p>Unfortunately, \/My Documents\/ suffers from all the same problems that plague the Windows registry. Microsoft created &#8220;one system to rule them all&#8221;, and then made the implementation ambiguous. And it didn&#8217;t really do everything it needed to do. And it created security concerns. And then they changed how it worked from one version of Windows to the next. <\/p>\n<p>For one thing, it&#8217;s not even called \/My Documents\/ these days. It&#8217;s \/Users\/. The location keeps changing. The internal structure keeps changing. The rules governing access keep changing. All of this creates problems for would-be game designers. Where do I put the user&#8217;s saves? <\/p>\n<p><!--more--><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr29_save2.jpg' class='insetimage'   alt='gr29_save2.jpg' title='gr29_save2.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>I can dump them into the root of the current logged in user:<\/p>\n<p>\/Users\/Bob<\/p>\n<p>(For this discussion, Let&#8217;s assume the current user is &#8220;Bob&#8221; and the game we&#8217;re making is called &#8220;Foo&#8221;<\/p>\n<p>Or perhaps:<\/p>\n<p>\/Users\/Bob\/My Documents<\/p>\n<p>Or maybe:<\/p>\n<p>\/Users\/Bob\/AppData<\/p>\n<p>Or one of these. <\/p>\n<p>\/Users\/Bob\/Saved Games\/<br \/>\n\/Users\/Bob\/Saved Games\/Foo<br \/>\n\/Users\/Bob\/Foo<br \/>\n\/Users\/Bob\/AppData\/Foo<br \/>\n\/Users\/Bob\/My Documents\/Foo<br \/>\n\/Users\/Bob\/My Documents\/my games\/Foo<\/p>\n<p>I can find examples of most of these on my computer, by the way. And this is to say nothing of non-English versions of Windows where SOME of the above will be replaced with localized values, thus multiplying the number of possible permutations. What a mess.<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr29_dir.jpg' class='insetimage' width='600' alt='For the record, the game in the misspelled folder is Dead Space.' title='For the record, the game in the misspelled folder is Dead Space.'\/><\/td><\/tr><tr><td class='insetcaption'>For the record, the game in the misspelled folder is Dead Space.<\/td><\/tr><\/table><\/p>\n<p>But maybe I shouldn&#8217;t put it in Bob&#8217;s directory. Maybe the saves ought to go someplace public so that all users can access the same saves?<\/p>\n<p>\/Users\/Public\/Public Documents\/[all the permutations from above]<\/p>\n<p>In my current version of Windows 7, some of the directories are hidden by default, so when the user goes searching for &#8220;batman&#8221; or &#8220;minecraft&#8221; to back up specific games, <em>they won&#8217;t find the files they need, even if they&#8217;re lucky enough to be looking in the right place and using the correct search terms<\/em>. <\/p>\n<p>Even if I do the homework and figure out what Microsoft really expects me to do, and even if the docs are clear, is it really going to offer me a reliable, predictable, sensible place to put these files? Will it be backwards compatible? What if the directory doesn&#8217;t exist because the user &#8220;cleaned up&#8221; this mess? Will my program have permission to create the needed directories? The odd thing about user permissions in Windows is that they pretty much ONLY apply to the \/Users\/ area and a couple of system folders. I could fill all hard drives with thousands of folders and the OS would never raise an eyebrow. From my perspective, \/Users\/ is the most dangerous place to save data because it&#8217;s the ONLY place where some unforeseen edge-case configuration might cause the game to crash or be unable to save, thus creating maddening support problems for ME. I could save files literally anywhere else with no risk.<\/p>\n<p>This creates a testing nightmare for anyone. Maybe Windows Vista Home Edition has some fussy difference that needs to be accounted for. Maybe I&#8217;d need a completely different solution for Windows XP.<\/p>\n<p><em>Bah, Windows XP is ancient. You shouldn&#8217;t support people that can&#8217;t be bothered to upgrade.<\/em><\/p>\n<p>You make it sound like I&#8217;m punishing THEM for not upgrading, but that&#8217;s no what&#8217;s going on. I&#8217;m the one being punished. XP still has a respectable market share and I&#8217;d be giving up a lot of potential sales by refusing to support those people. By cutting off XP users I&#8217;m hurting myself and <em>rewarding<\/em> Microsoft for their half-assery. (By creating additional pressure for the user to upgrade.) I&#8217;m giving up sales so I can be a shill for the idiots who created the problem in the first place. That&#8217;s messed up.<\/p>\n<p>Worse, all of this extra work, worry, testing, and support, applies only to Microsoft-based systems. It&#8217;s work that doesn&#8217;t need to be done for (say) Mac or Linux. (Assuming a developer is planning on developing for those platforms.) <\/p>\n<p>The path of least resistance is to just ignore all of these Microsoft shenanigans. Just create a save game folder wherever the program is currently running. This way the game will work the same way on all platforms, I&#8217;ll always have read\/write permission, and we don&#8217;t have to worry about littering the user&#8217;s documents directory with abandoned files when the game is uninstalled. It&#8217;s neat, it&#8217;s clean, it&#8217;s easy, and it&#8217;s self-contained.<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr29_save1.jpg' class='insetimage' width='600' alt='The diamond shape on the right side is for debugging. It shows me the position of a spawn point where a story node or robot COULD have spawned' title='The diamond shape on the right side is for debugging. It shows me the position of a spawn point where a story node or robot COULD have spawned'\/><\/td><\/tr><\/table><\/p>\n<p>Looking at the \/Users\/ directory on my computer, it looks like a lot of indies have come to the same conclusion. I have a lot of indie games installed, and precious few of them appear in \/Users\/. That space is overwhelmingly dominated by AAA titles, and I&#8217;m willing to bet that indies are just saving the game under the current working directory.<\/p>\n<div class=\"dmnotes\">Maybe &#8220;current working directory&#8221; needs some explanation?<\/p>\n<p>The CWD is where THIS program is running. If you base everything off the CWD, then you never need to know about or care what drive you&#8217;re on. <\/p>\n<p>If the game is installed to:<\/p>\n<p>C:\/Games\/Foo<\/p>\n<p>Then that will be the CWD when the game is run.  If I create a &#8220;save&#8221; folder without telling the OS specifically where to put it, then it will end up in the CWD like so:<\/p>\n<p>C:\/Games\/Foo\/save<\/p>\n<p>If the user moves the game to (say) <\/p>\n<p>D:\/Games\/Indie\/Shooters\/Foo<\/p>\n<p>&#8230;then the game won&#8217;t suffer or get confused. In fact, the game won&#8217;t even know that the move took place. Saves will appear in:<\/p>\n<p>D:\/Games\/Indie\/Shooters\/Foo\/save<\/p>\n<p>and everything will be fine. <\/p><\/div>\n<p>So that&#8217;s what I&#8217;ve been doing. Cutting corners and cursing Microsoft. I strongly suspect that it&#8217;s no accident that the more you try to be cross-platform, the more of a pain in the ass it is to support Microsoft. <\/p>\n<p><strong>EDIT:<\/strong> As someone pointed out below, with my current setup if the game is installed to \/Program Files\/ then the user would need to run as administrator in order to save the game.  That won&#8217;t do.<\/p>\n<p>Screw this. I&#8217;ll just hard-code the game to save everything to <\/p>\n<p>C:\/butts\/<\/p>\n<p>That should make everyone happy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Players expect to be able to save their game. Which creates the question of, &#8220;Where do we store those saves?&#8221; Previously we&#8217;ve seen some surprisingly lively debates around the subject in the comments. I can&#8217;t find it now, but one person even went so far as to say that if a game doesn&#8217;t save in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[498],"tags":[],"class_list":["post-21611","post","type-post","status-publish","format-standard","hentry","category-good-robot"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21611"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21611\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}