This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ComputerCraftFan11's profile picture

Floppy installer?

Started by ComputerCraftFan11, 06 March 2012 - 04:24 AM
ComputerCraftFan11 #1
Posted 06 March 2012 - 05:24 AM
I'm creating a factory that has a turtle that spawns other turtles right next to a disk drive with a floppy inside. How can I make the floppy automatically install a program into the turtle's startup?
Liraal #2
Posted 06 March 2012 - 06:02 AM
fs.copy("disk/turtleStartup", "startup")
Espen #3
Posted 06 March 2012 - 11:14 AM
@ComputerCraftFan11:
You have to make the turtle check for a disk drive on its side (not the one with the modem on it though, that is used up by the modem).
For this you can use the disk API (see 'help disk') + the fs API (see 'help fs').
Basically you go through these steps within a loop:
  • Is there a disk on a specific side? disk.isPresent( side )
  • Does the disk have data? disk.hasData( side )
  • If so, then get its mount path. disk.getMountPath( side )
  • Add add the name of the file to be copied from the disk ("startup") to the mount path of the disk. fs.combine( diskMountPath, PathOfFileToCopy )
  • Now you finally copy this combined path from the disk to your turtle. fs.copy( SourcePath, TargetPath )
Of course you can/should do some checks in between, like: Does the file "startup" exist? If yes then do …, if no then do …., etc.
Hope this primer gives you an idea where to start. :unsure:/>/>
Sebra #4
Posted 12 March 2012 - 03:29 PM
If his startup file is on floppy in disk drive, than at the run time he is sure of floppy existence and content. :mellow:/>/>
Espen #5
Posted 12 March 2012 - 09:44 PM
If his startup file is on floppy in disk drive, than at the run time he is sure of floppy existence and content. :mellow:/>/>
That might be true in this specific case, but I'm always trying to program functions as dynamically as possible, so that they don't necessarily fit one specific case, but can be used for multiple purposes. That means that I never just assume anything as a given, but always make proper checks.
This way if the function is not used properly in another program, it won't stop due to errors.
ComputerCraftFan11 #6
Posted 12 March 2012 - 11:57 PM
i modified the mods/computercraft/lua and changed the startup to detect if there is a disk and if true then run it.

It worked :mellow:/>/>
Cloudy #7
Posted 13 March 2012 - 01:52 AM
You do realise that computercraft supports booting from a startup file on a disk with no alterations right?
ComputerCraftFan11 #8
Posted 13 March 2012 - 06:25 AM
You do realise that computercraft supports booting from a startup file on a disk with no alterations right?

then ill have to open it and write the entire code and save it and reboot the turtle and do that each time.
and yes i do know that but my way works easier
Espen #9
Posted 13 March 2012 - 11:12 AM
You do realise that computercraft supports booting from a startup file on a disk with no alterations right?
then ill have to open it and write the entire code and save it and reboot the turtle and do that each time. and yes i do know that but my way works easier
If it works easier, then would you mind sharing it? This way everyone can benefit and maybe it will be included in the next release. :mellow:/>/>