←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Updating turtle programs

Justinjah91's Photo Justinjah91 10 Oct 2018

Good afternoon!

So I keep all of my turtle programs on a single disk so I only have to edit the programs in one place. Any time I make changes to those programs, I update my turtles by running an update script that looks like this:

local programs = {"branch","dig","dump","loggerpro","move","obsidian","processgravel","room","safebranch","shaft","sort","sortwrapper"}

for i=1,#programs do
shell.run('delete',programs[i])
shell.run('copy','/disk/'..programs[i],programs[i])
end

print('All programs updated!')

As you can see, I manually enter the names of the programs into a table (or array, or matrix, or whatever they are called in LUA) to do this. I'm wondering if there is a way to automatically detect which programs a turtle already has installed and only attempt an update if the disk contains the same program. In other words, is there a way to avoid having to manually type in the names of all of the programs on the disk? It isn't a huge deal since there aren't very many programs here, I was just curious if it COULD be done.
Quote

Bomb Bloke's Photo Bomb Bloke 11 Oct 2018

fs.list() gets you a table with all the contents of a given path. After pulling listings for both your turtle's drive and the floppy disk, you need only compare them and update any files found in both locations.
Quote

campicus's Photo campicus 11 Oct 2018

Not what you're looking for but your question has already been answered so... you might find this useful? Check out the program I made to automatically pull all the pastes from your pastebin. There's also a 'refresh' program I just added, which automatically updates all your programs when you place the comp/turtle next to the disk drive.
1. Run the update program on a computer above a disk drive (with a disk in it).
2. Place your turtle/computer next to the disk drive, open it
3. You'll be prompted to add a label (if it's not labelled) and set a startup program (leave blank to not set one)
4. Fully updated comp/turtle!

Update: https://pastebin.com/BB7dQGu2
Spoiler

Refresh: https://pastebin.com/9mTVTruQ
Spoiler

Edited by campicus, 11 October 2018 - 01:02 AM.
Quote