Log In  

Hi!

I'd like to rename the older Pico-8 games that are only labeled as numbers. I know the game name can be seen in the first few lines of code - so I was hoping for an automated method using a script or program or something since there are several thousand of them.

Thanks!!

P#116070 2022-08-20 20:20

That depends on your preferred programming languages and/or which OS you're using. The name is the 4th line of the ".p8" file. As long as you have them all in the same folder, there's a way with basically any language make a quick program to walk through each and make the necessary changes. In addition, all versions linux have built-in stuff that is powerful enough to do that task through a batch file. I think windows batch files might be able to as well, but I'm not sure. I've also notice python seems to be a really common go-to for scripting tasks.

That said, if you want a solution that uses Lua (thus being similar to programming in pico-8), you can download one of the binaries for standard Lua and run a script through it (using the documentation, since standard Lua has completely different built-in functions). However, there's a minor issue to deal with: by default Lua doesn't have any way to search a folder. This is because that task is dependent on the type of file system and the OS's choice for how to interact with it, thus putting it beyond basic C, which Lua is limited to. There's 3 ways you can get around that. One is to grab an extension that adds that ability, such as LuaFileSystem. Another is to learn how to use the popen() function, which apparently can do it somehow.

The third way is simply to already know what pattern the files will have and iterate. For example, if you happen to have named all the games in the pattern 1.p8, 2.p8, etc., then this code would work:

-- num_games being however many you're renaming
for i=1,num_games do
  local f = io.open(i..".p8")
  if f then -- in case it can't be found
    local s = ""
    local n = 1
    for l in f:lines() do
      if n == 4 then
        s=s.."--"..new_names[n].."\n"
      else
        s=s..l.."\n"
      end
    end
    local outf = io.open(new_name[n]..".p8","w")
    outf:write(s)
  end
end

From there, the os.execute() function can be used if you then want to have pico-8 run and make other builds for each one. The pico-8 manual has a section labeled "Commandline parameters", and among them is the parameter -export which you can use for building via an external script.

All that said, the biggest issue with the task in question is how you're going to supply the script with all the new names.

P#116075 2022-08-20 21:35
1

Sounds like a tool could be made to handle this, @KillerQ.

Though I'm not sure everyone always says the name of their project in the first few lines. I do - but that's because I saw it appears in SPLORE.

P#116094 2022-08-21 13:29

Yea, I'm using windows and using the pico tool to browse the code. You're right - although many do mention the name in the beginning lines of the code, not all do. That's going to make an automated tool useless. Ugh. I wish there weren't so many thousands that don't have the file name the same as the game. Haha. Back to the drawing board I suppose.

Thanks again.

P#116099 2022-08-21 14:37

Thousands? Are you just ripping the bbs?

P#116105 2022-08-21 16:10

@VgBlade,

I had a few dozen that I downloaded myself that have the regular file names, but someone gave me a bunch of them in a folder that have the older naming style. I just figured it would be cool to be able to see their proper name in the filename.

P#116106 2022-08-21 16:18

I feel like the best way would just to load your program, like just copy and paste it, into something else like VScode and use their function to change variable names.

P#132360 2023-07-25 05:56

look into https://github.com/thisismypassport/shrinko8#custom-python-script -- the cart's title can be read like this:

def preprocess_main(cart, args, **_):
    print(cart.title)

run the script (title-extract.py) like this:
shrinko8 15133.p8 --script title-extract.py

P#132430 2023-07-26 21:19 ( Edited 2023-08-17 07:24)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 18:22:06 | 0.057s | Q:20