As far as I know, a chunkloaded turtle is the same as a turtle in a chunk loaded area in that it won't restart unless the game restarts (or if you program it reboot, I don't know what will happen then). Making a chunk loader turtle is only necessary for things like mining turtles. If the turtle is in a chunkloaded space at all times it will also be fine.
The fs api is what you can use to work around with the
file
system, hence the name. Every program you write gets saved by default in a directory that you can access by typing "dir" into the command line (without the speech marks). You should see a list of all the programs you have saved, and depending on your mods there might be other stuff (particularly if you have open peripherals).
You aren't limited to saving programs to files, you could even write a story and save it as though you were using a word processor. More importantly, you can code the computer or turtle to read and write files. I am fairly new to this but I have now written a few working programs. I might not be doing it the very best way, but it is functional and I will try and explain it as best as I can.
I have found the two most useful functions in the fs api are as follows
Code:
fs.exists([I]string [/I]name of the file you are checking inside speech marks) -- this checks to see if a file exists in your directory. Useful for checking if a save file is being created for the first time and other similar stuff
fs.open([I]string[/I] name of the file again in speech marks,[I] string[/I] mode also in speech marks) -- the name of the file business is the same as with the other command. the mode allows you to specify whether you are opening the file in read only mode or writing mode or appending mode.
An important feature of fs.open is if the file you specify doesn't exist, it will create it (at least it does in write mode I haven't tested it in the other modes because the only reason I would ever open a new file is to write to it. I use fs.exists() to check if it needs creating)
fs.open is quite a complicated command because it doesn't do too much on its own, its more like wrapping a peripheral, only in this case the peripheral isn't a modem ore a chunk loader it is a file in the file system.
There are new commands (well they aren't really knew, they are very similar to read() and write()) that are exposed when you open a file with fs.open so you can manipulate the file, but first you need a handle on that file in the form of a variable (sorry, that was garbled I hope it makes sense).
Code:
local file = fs.open("saveData", "w") --[[ this attaches the handle to the variable file. you call later commands using this variable. the "w" shows that we have opened it in write mode]]
--now we can write a line to the file
file.write("data, 42, mac and cheese")
-- [[that line will appear on that file (which you can access by typing dir in the command line later). But before it gets saved
you need to close the file like so]]
file.close() --and it is as simple as that
--reading a file is very similar except you replace the "w" with an "r"
file = file.open("saveData", "r")
then we can say
local data = file.readAll() -- this saves the contents of the file to a variable that the current program can use. *(edited by me because I derped. I forgot to save it to a variable last time)
file.close()
-- which will return
>data, 42, mac and cheese
There is a bit more to it than that but there are the basics. fs.open() and all its sub commands are explained very well on this link to a part of the computercraft wiki
http://computercraft.info/wiki/Fs.open
Also, I find it is helpful to save serialized tables (you can serialize a table using the textutils api). They can be unserialized when you load them and I think they are practical at carrying your data.
When I write save files they usually just contain some important variables that can't be generated/discovered by the turtle
without my input and if it is a moving turtle I will add a short string that a returnHome() function in my program can interpret so the turtle can discover its starting position and go their to reset so it doesn't bung up its routing.
Sorry if that was a bit of a chore to read, but I hope it is at least clear enough to introduce the basics so you can get the most from the links.
Edit: Thats my second long rambling on this subject, sorry ladies and gentlemen, I will be quiet(er) now
Second edit: I made a mistake (sue me I'm very tired
). I just wanted to let people know what it is so they don't make the same mistake. I have marked the mistake in the text with an asterisk(*). What I did was forgot to save the result of reading the file to a variable. It was a very simple fix though, you simply have to wrote local variableName = file.readAll(). Sorry if this led to confusion