This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Transferring programs using floppy disks
Started by bigbaddevil6, 18 April 2014 - 05:52 AMPosted 18 April 2014 - 07:52 AM
So I decided that I wanted to make my own version of a gps tower builder. I got everything needed except I'm unsure on how to do the transferring the info to a floppy disk then loading it onto the computer.
Posted 18 April 2014 - 11:09 AM
Write a couple of scripts and put them on the disk. The first can be labelled "startup": rig it to copy the second to the drive of the computer that runs it. The second script can handle the actual GPS server code.
Each time the turtle places the disk drive and disk, it can re-write the second script with the co-ordinates where the new computer is being placed. Simple enough, as that should only consist of a single line.
Is it disk drives that you're unfamiliar with, or the commands you'd use to copy / re-write files?
Each time the turtle places the disk drive and disk, it can re-write the second script with the co-ordinates where the new computer is being placed. Simple enough, as that should only consist of a single line.
Is it disk drives that you're unfamiliar with, or the commands you'd use to copy / re-write files?
Posted 18 April 2014 - 11:49 AM
When the disk drive is placed you can copy the files from the disk in the disk drive to the Computer using the FS API (http://computercraft...ki/Fs_%28API%29).
This can be done with:
Edit: Sorry, I did not read your post carefully. If I understand you right, the thing you want to do is to insert a disk into a disk drive attached to a computer, copy a file onto the computer and then run it. That would be possible with copying a file called "startup" to the computer because this file is the first program to run when booting the computer.
This can be done with:
fs.move("/disk/filetomove", "/placetobe")
I hope this is what you were searching for.Edit: Sorry, I did not read your post carefully. If I understand you right, the thing you want to do is to insert a disk into a disk drive attached to a computer, copy a file onto the computer and then run it. That would be possible with copying a file called "startup" to the computer because this file is the first program to run when booting the computer.
Edited on 18 April 2014 - 09:53 AM
Posted 18 April 2014 - 05:39 PM
Write a couple of scripts and put them on the disk. The first can be labelled "startup": rig it to copy the second to the drive of the computer that runs it. The second script can handle the actual GPS server code.
Each time the turtle places the disk drive and disk, it can re-write the second script with the co-ordinates where the new computer is being placed. Simple enough, as that should only consist of a single line.
Is it disk drives that you're unfamiliar with, or the commands you'd use to copy / re-write files?
Mainly the commands. I never had much luck with them.
Posted 19 April 2014 - 02:31 AM
Well, say you want to have the turtle write a GPS host-starting script onto the disk. You might use something like:
The startup script you'd place on the disk might read along the lines of:
Once the turtle has placed the disk drive and disk, it would then move a step to the side, place the computer, and boot it via its peripheral command API:
It can then go collect the disk drive (which would give the computer enough time to perform its file copy), move back next to the computer, and reboot it.
local newX, newY, newZ = 345,4,24
local compyScript = fs.open("disk/GPSScript","w")
compyScript.writeLine("shell.run(\"gps host "..newX..","..newY..","..newZ.."\")")
compyScript.close()
The startup script you'd place on the disk might read along the lines of:
shell.move("disk/GPSScript","startup")
Once the turtle has placed the disk drive and disk, it would then move a step to the side, place the computer, and boot it via its peripheral command API:
local compy = peripheral.wrap("front")
compy.turnOn()
It can then go collect the disk drive (which would give the computer enough time to perform its file copy), move back next to the computer, and reboot it.
Posted 20 April 2014 - 03:22 AM
The startup script you'd place on the disk might read along the lines of:shell.move("disk/GPSScript","startup")
So the shell.move would already be on the disk? Here is so far of what I got. It does the writing but it doesn't have the startup script. In fact I got the whole thing working except for that startup script. The full code will be linked below.
function transfer(Cnum)
file = fs.open("disk/startup", "w")
if Cnum == 1 then
file.writeLine("shell.run(\"gps\",\"host\","..C1x..","..C1y..","..C1z..")")
elseif Cnum == 2 then
file.writeLine("shell.run(\"gps\",\"host\","..C2x..","..C2y..","..C2z..")")
elseif Cnum == 3 then
file.writeLine("shell.run(\"gps\",\"host\","..C3x..","..C3y..","..C3z..")")
elseif Cnum == 4 then
file.writeLine("shell.run(\"gps\",\"host\","..C4x..","..C4y..","..C4z..")")
end
file.close()
end
http://pastebin.com/cjxyVgqB
Edited on 20 April 2014 - 01:24 AM
Posted 20 April 2014 - 04:51 AM
Yes, the idea is that you'd manually put the file-moving/copying startup script on the disk yourself, then just leave it on there.
The file the turtle would write to the disk would have a name other then "startup" - on its first boot, you don't want the computer to immediately go into GPS mode, you want it to copy the GPS script to its internal drive.
There are plenty of deviations you could make to this plan. There's no "one way" it has to be done.
The file the turtle would write to the disk would have a name other then "startup" - on its first boot, you don't want the computer to immediately go into GPS mode, you want it to copy the GPS script to its internal drive.
There are plenty of deviations you could make to this plan. There's no "one way" it has to be done.
Posted 20 April 2014 - 05:52 AM
hmmm. So I made I made the startup script, which I did like.
And I changed my file that is opened to.
Yet when it runs it just returns nil in the startup program. I checked and the directory is being made on the disk, and getting cords stored in it. The ste my program does is: Places computer, moves up and places modem, moves down two places drive and disk, then goes up, turns on the computer, then goes back for the disk and drive.
To my understanding all where doing is making a file on the disk to store then info then when the computer is turned on it moves the file over. It seems simple enough to me so I don't know how I messed it up. My guess is a stupid mistake I did somewhere.
Here's the Startup script screenshot http://puu.sh/8fPY3/862858debc.png
Here's the Opening of the file http://puu.sh/8fQ1O/dae1026ad8.png
shell.move("disk/GPS", "startup")
And I changed my file that is opened to.
file = fs.open("disk/GPS", "w")
Yet when it runs it just returns nil in the startup program. I checked and the directory is being made on the disk, and getting cords stored in it. The ste my program does is: Places computer, moves up and places modem, moves down two places drive and disk, then goes up, turns on the computer, then goes back for the disk and drive.
To my understanding all where doing is making a file on the disk to store then info then when the computer is turned on it moves the file over. It seems simple enough to me so I don't know how I messed it up. My guess is a stupid mistake I did somewhere.
Here's the Startup script screenshot http://puu.sh/8fPY3/862858debc.png
Here's the Opening of the file http://puu.sh/8fQ1O/dae1026ad8.png
Posted 20 April 2014 - 06:33 AM
Can you please elaborate on what "returns nil" means here?
Posted 20 April 2014 - 08:18 AM
This is all it give me. http://puu.sh/8fWTe/5a2bca715e.png meant to word it better when I said it.
Posted 20 April 2014 - 09:28 AM
Ah. It's "fs.move", not "shell.move". Don't mind me.
Posted 21 April 2014 - 04:48 AM
Alright I finished it. I even added an additional line to create the startup file on the disk so it doesn't have to be added manually. I did run into an interesting problem with the turtle turning it on then having to reboot it again. The turtle will not reboot the computer until a certain amount of time has passed. I found to be 3 seconds before it can reboot it. It's nothing to worry about because the program works lovely. Also learning how to properly move files like that is gonna help tremendously with future programs I plan doing.