PhasecoreX [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=91782 Questions About LS() Function <p>I have two issues with the <code>ls()</code> function. Any help with them or workarounds would be highly appreciated!<br /> Also hello! This is my first post!</p> <h2>Custom File Extensions</h2> <p>I am making a game that involves a level editor. I have the code save these packs of levels with a custom extension using <code>cstore()</code>, one that is different than <code>.p8</code>. It saves just fine, as it's technically a <code>.p8</code> file with a custom extension. For the sake of argument, let's say the extension is &quot;levels&quot;, so my <code>cstore()</code> looks like:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>cstore(0x0, 0x8000, 0x4300, filename..&quot;.levels&quot;)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I'm also able to load from that created file, like so:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>reload(0x8000, 0x0, 0x4300, filename..&quot;.levels&quot;)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>The issue I am now facing is that I want to be able to list all of the files in the directory that have this custom file extension, so that the user can choose the level pack to play. However, the <code>ls()</code> function only returns files that end with <code>.p8</code> and <code>.p8.png</code>. Is it possible to have it list only files with a certain extension, or at least list all files?</p> <p>I don't really want to save my level packs as <code>.p8</code> files, as they aren't really a runnable cartridge. They are a bunch of garbage graphics data with no code. And even if they are technically still a cartridge, I don't want them showing up in splore's root file browser or something like ES-DE, and I want my game to easily know which are level packs it can read.</p> <h2>Working Directory</h2> <p>My game is in a subdirectory in the root folder of pico-8 while I develop it, like so:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>/mygame/mygame.p8 /mygame/main.lua /mygame/map.lua /mygame/util.lua</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>When I do the above <code>cstore()</code>, the file is created in the subdirectory that the game is running from:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>/mygame/mygame.p8 /mygame/levelpack.levels &lt;-- here /mygame/main.lua /mygame/map.lua /mygame/util.lua</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>But if I do <code>ls()</code> in the game, it looks in the root folder only:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>mygame/</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I get that I could do <code>ls(&quot;mygame&quot;)</code>, but once I export it to <code>.p8.png</code>, it probably won't be in a subdirectory anymore. Is there a way that I can tell <code>ls()</code> to look in the directory that the game is currently running from? Or, a way to get the current working directory so I can pass it to <code>ls()</code>?</p> https://www.lexaloffle.com/bbs/?tid=140495 https://www.lexaloffle.com/bbs/?tid=140495 Sun, 03 Mar 2024 22:10:46 UTC