Log In  
Follow
PhasecoreX
[ :: Read More :: ]

I have two issues with the ls() function. Any help with them or workarounds would be highly appreciated!
Also hello! This is my first post!

Custom File Extensions

I am making a game that involves a level editor. I have the code save these packs of levels with a custom extension using cstore(), one that is different than .p8. It saves just fine, as it's technically a .p8 file with a custom extension. For the sake of argument, let's say the extension is "levels", so my cstore() looks like:

cstore(0x0, 0x8000, 0x4300, filename..".levels")

I'm also able to load from that created file, like so:

reload(0x8000, 0x0, 0x4300, filename..".levels")

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 ls() function only returns files that end with .p8 and .p8.png. Is it possible to have it list only files with a certain extension, or at least list all files?

I don't really want to save my level packs as .p8 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.

Working Directory

My game is in a subdirectory in the root folder of pico-8 while I develop it, like so:

/mygame/mygame.p8
/mygame/main.lua
/mygame/map.lua
/mygame/util.lua

When I do the above cstore(), the file is created in the subdirectory that the game is running from:

/mygame/mygame.p8
/mygame/levelpack.levels   <-- here
/mygame/main.lua
/mygame/map.lua
/mygame/util.lua

But if I do ls() in the game, it looks in the root folder only:

mygame/

I get that I could do ls("mygame"), but once I export it to .p8.png, it probably won't be in a subdirectory anymore. Is there a way that I can tell ls() 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 ls()?

P#142371 2024-03-03 22:10 ( Edited 2024-03-03 22:10)