Posted 26 March 2014 - 02:56 PM
I have really appreciated the ComputerCraft mod as part of the Direwolf20 modpack. I've spent a bit of time building a few programs that I thought were worth sharing back to the community. It's not the best code I've ever written but LUA is a new language to me so I'm learning as I go. There are a few things that could use some work but over all it's functional. If you have a suggestion on how to improve, feel free to update the code and if it makes sense to me, I'll update the originals.
My general thought process is that I've built reusable libraries to do the bulk of the work and then written smaller programs to use those libraries to accompllish meaningful things which speeds up my ability to make new programs. As a convention, all of my programs expect slot number 15 to contain fuel and only uses what's necessary as needed. If it needs fuel and does not have any in slot 15, it will simply wait until fuel is added then continue where it left off. To get started, download the 'update' program from pastebin:
pastebin get 16Fi7BAZ update
This program is used to fetch all other programs. I wrote it because I got tired of looking up pastebin IDs every time I modified
code. To use it, simply run:
update <ProgramName>
For example, if there have been updates to the update program, you would run "update update". Installing new programs are done using the same command providing that program has been registered in the update program. (ie: update makefloor to install the makefloor program)
The first place to start is to fetch all of the libraries as nearly every program I write uses them. The easiest thing to do is to update all libraries:
update lib all
Here are the help files for some key programs I've written. If in doubt, you can always execute the program with no arguments for a reminder on how to use it.
turn [right|left|around]
Turns the turtle in place
go [up|down|forward|backward] <distance>
Moves a specified direction a giiven number of places
makewall <length> <height>
Builds a wall using the items in inventory slots nubmer 1 thru 13. If it runs out of items, it will wait for you to refill.
makefloor <length> <width> [right|left]
Makes a floor (or flat roof) of a givenlength and width using the items in inventory slots nubmer 1 thru 13, building the
square to the right or left of the turtle's starting position. If it runs out of items, it will wait for you to refill.
makebox <length> <width> <Height> [right|left]
Makes a box of given dimensions. Exacly like making 4 walls in a single command (I got tired of repositioning the turtle for my next wall)
dig [top|front|bot]
If you have a mining Turtle, this will break the block in the given direction and add it to inventory. Great way to fetch things out of lava.
digline <length> [top|front|bot]
Digs in a straight line of given length, removing all blocks in the given direction (above, below, or in front of the turtle) There's still alot to be desired on this one; I wrote it real quick when I accidently placed down a large wall in the wrong place.
If you want to take a look at my code, the pastebin IDs are all in the first few lines of the update program but here's the current list. Should be easy enough to add your own programs but those changes will be overwritten if you update update. I hope to change the update program to use a seperate text file in the future so that you can add your own custom list that will not be overwritten but have not begun to work on that yet:
update="16Fi7BAZ",
turn="tpgKGzxz",
go="H20vyESA",
makewall="4n2zP1UJ",
makefloor="hwePkhJg",
makebox="26HuG7uZ",
dig="A8GUg9kR",
digline="LEm9jTdV",
eat="mhuCCZ2C"
}
libraries = {
movelib="pwYgswUu",
rednetlib="ZPtvJULc",
peripherallib="Q4AwfDuu",
buildlib="vhtPCC8S"
}
My general thought process is that I've built reusable libraries to do the bulk of the work and then written smaller programs to use those libraries to accompllish meaningful things which speeds up my ability to make new programs. As a convention, all of my programs expect slot number 15 to contain fuel and only uses what's necessary as needed. If it needs fuel and does not have any in slot 15, it will simply wait until fuel is added then continue where it left off. To get started, download the 'update' program from pastebin:
pastebin get 16Fi7BAZ update
This program is used to fetch all other programs. I wrote it because I got tired of looking up pastebin IDs every time I modified
code. To use it, simply run:
update <ProgramName>
For example, if there have been updates to the update program, you would run "update update". Installing new programs are done using the same command providing that program has been registered in the update program. (ie: update makefloor to install the makefloor program)
The first place to start is to fetch all of the libraries as nearly every program I write uses them. The easiest thing to do is to update all libraries:
update lib all
Here are the help files for some key programs I've written. If in doubt, you can always execute the program with no arguments for a reminder on how to use it.
turn [right|left|around]
Turns the turtle in place
go [up|down|forward|backward] <distance>
Moves a specified direction a giiven number of places
makewall <length> <height>
Builds a wall using the items in inventory slots nubmer 1 thru 13. If it runs out of items, it will wait for you to refill.
makefloor <length> <width> [right|left]
Makes a floor (or flat roof) of a givenlength and width using the items in inventory slots nubmer 1 thru 13, building the
square to the right or left of the turtle's starting position. If it runs out of items, it will wait for you to refill.
makebox <length> <width> <Height> [right|left]
Makes a box of given dimensions. Exacly like making 4 walls in a single command (I got tired of repositioning the turtle for my next wall)
dig [top|front|bot]
If you have a mining Turtle, this will break the block in the given direction and add it to inventory. Great way to fetch things out of lava.
digline <length> [top|front|bot]
Digs in a straight line of given length, removing all blocks in the given direction (above, below, or in front of the turtle) There's still alot to be desired on this one; I wrote it real quick when I accidently placed down a large wall in the wrong place.
If you want to take a look at my code, the pastebin IDs are all in the first few lines of the update program but here's the current list. Should be easy enough to add your own programs but those changes will be overwritten if you update update. I hope to change the update program to use a seperate text file in the future so that you can add your own custom list that will not be overwritten but have not begun to work on that yet:
Spoiler
programs = {update="16Fi7BAZ",
turn="tpgKGzxz",
go="H20vyESA",
makewall="4n2zP1UJ",
makefloor="hwePkhJg",
makebox="26HuG7uZ",
dig="A8GUg9kR",
digline="LEm9jTdV",
eat="mhuCCZ2C"
}
libraries = {
movelib="pwYgswUu",
rednetlib="ZPtvJULc",
peripherallib="Q4AwfDuu",
buildlib="vhtPCC8S"
}