Chapter 1: Getting Started with ComputerCraft
Chapter 3: Talking to Your Turtle
Chapter 4: Programming Turtles to Dance
Chapter 5: Making a Better Dancer
Chapter 6: Programming a Robot Lumberjack
Chapter 7: Creating Modules to Reuse Your Code
Chapter 8: Running an Automated Tree Farm
Chapter 9: Building a Cobblestone Generator
Chapter 10: Making a Stone Brick Factory
Chapter 11: Constructing Walls
Chapter 12: Constructing Rooms
Chapter 13: Constructing Floors
Chapter 14: Programming a Robotic Farm
1
GETTING STARTED WITH COMPUTERCRAFT
Installing Minecraft, ATLauncher, and ComputerCraft
Downloading and Installing ATLauncher
Downloading and Installing ComputerCraft
Minecraft Game Mode Differences
Running Programs in the Turtle GUI
Getting Started with Lua Programming
Goodbye Lua: Exiting Lua’s Prompt
That’s So Random: Generating Random Numbers
Checking the Turtle’s Fuel Levels
Teaching Your Turtle to Say Hello!
Listing All Files with the ls Command
Displaying Text with the print() Function
Stringing Strings Together with Concatenation
Getting Keyboard Input with the io.read() Function
Bonus Activity: Proper Introductions
Giving Text a Typewriter Effect
Bonus Activity: A Turtle by Any Other Name
Experimenting with Moving the Turtle
Bonus Activity: New Dance Moves
Sharing and Downloading Programs Online
Writing a Better Dance Program
Making Decisions with if Statements
Comparing Two Values with Comparison Operators
Making Alternate Decisions with elseif Statements
Making a Decision . . . or Else!
6
PROGRAMMING A ROBOT LUMBERJACK
Designing a Tree-Chopping Algorithm
Detecting Blocks with the Turtle Detection Functions
Terminating Programs with the error() Function
Mining Blocks with the Turtle Digging Functions
Comparing Blocks with the Turtle Comparison Functions
Startup Programs and the shell.run() Function
7
CREATING MODULES TO REUSE YOUR CODE
Creating Functions with the function Statement
Loading a Module with the os.loadAPI() Function
Experimenting with the hare Module
Looking at the Turtle’s Inventory
Counting the Number of Items in a Slot
Getting Item Details from a Slot
Examining the Table Returned by the turtle.getItemDetail() Function
Finding an Item with a for Loop
Selecting an Empty Inventory Slot
Bonus Activity: Dance Move Module
8
RUNNING AN AUTOMATED TREE FARM
Designing a Tree-Farming Program
Loading Modules with the os.loadAPI() Function
Checking for Files with the fs.exists() Function
Selecting Saplings in the Turtle’s Inventory
Inspecting Blocks and Waiting for the Tree to Grow
Breaking Out of Loops with break Statements
Running Other Programs with the shell.run() Function
Handling Items with the Turtle’s Drop Functions
Rewriting Your Code for When You Have No Bone Meal
Bonus Activity: Lone Turtle Farmer
9
BUILDING A COBBLESTONE GENERATOR
Blueprints for the Cobblestone Generator
Setting Up Furnaces for Smelting the Cobblestone
Setting Up Your Program and Making a Constant Variable
Mining the Cobblestone from the Generator
Making Code Readable with Constants
Dropping the Cobblestone into the Furnaces
Rounding Numbers with the math.floor() and math.ceil() Functions
Calculating the Cobblestone to Distribute in Each Furnace
Moving the Cobblestone Miner Back into Position
Bonus Activity: Cobble Together More Cobblestone Furnaces
10
MAKING A STONE BRICK FACTORY
Designing a Program to Craft Stone Bricks
Writing the brickcrafter Program
Running the brickcrafter Program
Setup for the brickcrafter Program
Collecting Stone from the Furnaces
Moving the Turtle Back into Position
Counting Inventory Items with countInventory()
Designing a Wall-Building Algorithm
Writing the buildWall() Function
Writing and Running the buildwall Program
Reading Command Line Arguments
Calling hare.buildWall() to Build a Wall
Bonus Activity: mylabel Program with Command Line Arguments
Designing a Room-Building Algorithm
Calculating the Total Number of Blocks Needed to Build a Room
Writing the buildRoom() Function
Bonus Activity: Plus-Shaped Rooms
Designing the Sweeping Algorithm
Returning to the Starting Position
Passing Functions to Functions
Calling the sweepFunc() Function
Moving Along the Rows and Columns
Figuring Out If a Number Is Even or Odd with the Modulus Operator
The Even-Width and Odd-Width Paths
Writing the buildFloor() Function
Writing the buildfloor Program
Running the buildfloor Program
Writing the buildcheckerboard Program
Running the buildcheckerboard Program
Writing the placeCheckerboard() Function
Calling the sweepField() Function
Bonus Activity: Different-Colored Checkerboards
Designing the Wheat-Farming Algorithm
Setup for the farmwheat Program
Writing Functions to Use in the Main Program
Bonus Activity: Giant Wheat Fields
Tips for Automating Other Kinds of Farming
Milking Cows and Shearing Sheep
15
PROGRAMMING A STAIRCASE MINER
Designing the Stair-Mining Algorithm
Writing the digUntilClear() and digUpUntilClear() Functions
Writing the stairminer Program
Running the stairminer Program
Setup for the stairminer Program
Checking the Turtle’s Inventory