Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
|
|
xviii | |
|
|
xviii | |
|
|
xix | |
|
|
xix | |
|
|
xx | |
|
|
xxi | |
|
|
xxi | |
1 Getting Started With Computercraft |
|
1 | (8) |
|
Installing Minecraft, ATLauncher, and ComputerCraft |
|
|
1 | (4) |
|
|
2 | (1) |
|
Downloading and Installing ATLauncher |
|
|
2 | (2) |
|
Downloading and Installing ComputerCraft |
|
|
4 | (1) |
|
|
5 | (2) |
|
|
6 | (1) |
|
Minecraft Game Mode Differences |
|
|
6 | (1) |
|
|
7 | (2) |
2 Programming Basics |
|
9 | (18) |
|
Getting Started with Turtles |
|
|
9 | (8) |
|
|
10 | (2) |
|
Running Programs in the Turtle GUI |
|
|
12 | (2) |
|
|
14 | (2) |
|
|
16 | (1) |
|
Getting Started with Lua Programming |
|
|
17 | (3) |
|
|
17 | (2) |
|
Goodbye Lua: Exiting Lua&aposs Prompt |
|
|
19 | (1) |
|
|
20 | (3) |
|
|
21 | (1) |
|
That&aposs So Random: Generating Random Numbers |
|
|
22 | (1) |
|
Storing Values with Variables |
|
|
23 | (2) |
|
Checking the Turtle&aposs Fuel Levels |
|
|
25 | (1) |
|
|
26 | (1) |
3 Talking To Your Turtle |
|
27 | (8) |
|
Teaching Your Turtle to Say Hello! |
|
|
28 | (2) |
|
Running the hello Program |
|
|
29 | (1) |
|
Listing All Files with the Is Command |
|
|
30 | (1) |
|
Displaying Text with the print() Function |
|
|
30 | (2) |
|
|
31 | (1) |
|
Stringing Strings Together with Concatenation |
|
|
31 | (1) |
|
|
32 | (1) |
|
Getting Keyboard Input with the io.read() Function |
|
|
33 | (1) |
|
Bonus Activity: Proper Introductions |
|
|
33 | (1) |
|
Giving Text a Typewriter Effect |
|
|
33 | (1) |
|
|
33 | (1) |
|
Bonus Activity: A Turtle by Any Other Name |
|
|
34 | (1) |
|
|
34 | (1) |
4 Programming Turtles To Dance |
|
35 | (12) |
|
|
36 | (1) |
|
Running the mydance Program |
|
|
37 | (1) |
|
Using Comments in Your Code |
|
|
38 | (1) |
|
Turtle Movement Functions |
|
|
38 | (1) |
|
Experimenting with Moving the Turtle |
|
|
39 | (1) |
|
|
40 | (1) |
|
Taking the Turtle for a Spin |
|
|
41 | (1) |
|
|
42 | (1) |
|
Bonus Activity: New Dance Moves |
|
|
42 | (1) |
|
Sharing and Downloading Programs Online |
|
|
42 | (3) |
|
Deleting Files Off the Turtle |
|
|
43 | (1) |
|
|
44 | (1) |
|
|
44 | (11) |
|
Bonus Activity: Maze Runner |
|
|
44 | (1) |
|
|
45 | (2) |
5 Making A Better Dancer |
|
47 | (12) |
|
Writing a Better Dance Program |
|
|
47 | (2) |
|
Running the mydance2 Program |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
50 | (1) |
|
Making Decisions with if Statements |
|
|
51 | (1) |
|
Comparing Two Values with Comparison Operators |
|
|
52 | (2) |
|
Making Alternate Decisions with elseif Statements |
|
|
54 | (1) |
|
|
54 | (1) |
|
Making a Decision...or Else! |
|
|
55 | (3) |
|
|
56 | (1) |
|
|
57 | (7) |
|
Bonus Activity: Watchturtle |
|
|
58 | (1) |
|
|
58 | (1) |
6 Programming A Robot Lumberjack |
|
59 | (12) |
|
Equipping Turtles with Tools |
|
|
60 | (1) |
|
Designing a Tree-Chopping Algorithm |
|
|
61 | (1) |
|
Writing the choptree Program |
|
|
62 | (1) |
|
Running the choptree Program |
|
|
63 | (1) |
|
Detecting Blocks with the Turtle Detection Functions |
|
|
64 | (4) |
|
|
64 | (1) |
|
|
65 | (1) |
|
|
66 | (2) |
|
Terminating Programs with the error() Function |
|
|
68 | (1) |
|
Mining Blocks with the Turtle Digging Functions |
|
|
68 | (1) |
|
Comparing Blocks with the Turtle Comparison Functions |
|
|
69 | (1) |
|
|
69 | (1) |
|
Startup Programs and the shell.run() Function |
|
|
70 | (1) |
|
Bonus Activity: Going Down |
|
|
70 | (1) |
|
|
70 | (1) |
7 Creating Modules To Reuse Your Code |
|
71 | (14) |
|
Creating Functions with the function Statement |
|
|
72 | (3) |
|
|
73 | (1) |
|
|
74 | (1) |
|
Making a Module of Functions |
|
|
75 | (3) |
|
Loading a Module with the os.loadAPI() Function |
|
|
76 | (1) |
|
Experimenting with the hare Module |
|
|
76 | (2) |
|
Looking at the Turtle&aposs Inventory |
|
|
78 | (3) |
|
Selecting an Inventory Slot |
|
|
79 | (1) |
|
Counting the Number of Items in a Slot |
|
|
79 | (1) |
|
Getting Item Details from a Slot |
|
|
80 | (1) |
|
|
80 | (1) |
|
Examining the Table Returned by the turtle.getItemDetail() Function |
|
|
81 | (1) |
|
|
81 | (1) |
|
Finding an Item with a for Loop |
|
|
82 | (1) |
|
Selecting an Empty Inventory Slot |
|
|
83 | (1) |
|
Bonus Activity: Dance Move Module |
|
|
83 | (1) |
|
|
84 | (1) |
8 Running An Automated Tree Farm |
|
85 | (14) |
|
Designing a Tree-Farming Program |
|
|
86 | (1) |
|
Writing the farmtrees Program |
|
|
87 | (1) |
|
Running the farmtrees Program |
|
|
88 | (1) |
|
|
89 | (1) |
|
Chunk Loading in Minecraft |
|
|
90 | (1) |
|
Loading Modules with the os.loadAPI() Function |
|
|
90 | (1) |
|
Checking for Files with the fs.exists() Function |
|
|
91 | (1) |
|
Selecting Saplings in the Turtle&aposs Inventory |
|
|
91 | (3) |
|
|
91 | (1) |
|
Inspecting Blocks and Waiting for the Tree to Grow |
|
|
92 | (2) |
|
Breaking Out of Loops with break Statements |
|
|
94 | (1) |
|
Running Other Programs with the shell.run() Function |
|
|
94 | (1) |
|
Handling Items with the Turtle&aposs Drop Functions |
|
|
94 | (2) |
|
Rewriting Your Code for When You Have No Bone Meal |
|
|
96 | (1) |
|
Bonus Activity: Lone Turtle Farmer |
|
|
96 | (1) |
|
|
97 | (2) |
9 Building A Cobblestone Generator |
|
99 | (14) |
|
Blueprints for the Cobblestone Generator |
|
|
100 | (1) |
|
Setting Up Furnaces for Smelting the Cobblestone |
|
|
101 | (1) |
|
Writing the cobminer Program |
|
|
102 | (1) |
|
Running the cobminer Program |
|
|
103 | (1) |
|
Setting Up Your Program and Making a Constant Variable |
|
|
103 | (1) |
|
Mining the Cobblestone from the Generator |
|
|
104 | (1) |
|
Interacting with Furnaces |
|
|
105 | (5) |
|
Making Code Readable with Constants |
|
|
106 | (1) |
|
Dropping the Cobblestone into the Furnaces |
|
|
106 | (1) |
|
Rounding Numbers with the math.floor() and math.ceil() Functions |
|
|
107 | (1) |
|
Calculating the Cobblestone to Distribute in Each Furnace |
|
|
108 | (2) |
|
Moving the Cobblestone Miner Back into Position |
|
|
110 | (1) |
|
Bonus Activity: Cobble Together More Cobblestone Furnaces |
|
|
110 | (1) |
|
|
111 | (2) |
10 Making A Stone Brick Factory |
|
113 | (14) |
|
Designing a Program to Craft Stone Bricks |
|
|
114 | (1) |
|
|
114 | (2) |
|
Writing the brickcrafter Program |
|
|
116 | (2) |
|
Running the brickcrafter Program |
|
|
118 | (1) |
|
Setup for the brickcrafter Program |
|
|
119 | (1) |
|
Checking the Turtle&aposs Fuel |
|
|
119 | (1) |
|
Collecting Stone from the Furnaces |
|
|
120 | (1) |
|
|
121 | (1) |
|
Moving the Turtle Back into Position |
|
|
122 | (1) |
|
Bonus Activity: Cake Factory |
|
|
123 | (1) |
|
Creating a Factory Building |
|
|
123 | (2) |
|
|
125 | (2) |
11 Constructing Walls |
|
127 | (16) |
|
Extending the hare Module |
|
|
128 | (9) |
|
Counting Inventory Items with countInventory() |
|
|
130 | (1) |
|
Selecting and Placing a Block |
|
|
130 | (1) |
|
Designing a Wall-Building Algorithm |
|
|
131 | (3) |
|
Writing the buildWall() Function |
|
|
134 | (3) |
|
Writing and Running the buildwall Program |
|
|
137 | (1) |
|
|
138 | (1) |
|
Using the Array Data Type |
|
|
138 | (1) |
|
Reading Command Line Arguments |
|
|
139 | (1) |
|
|
139 | (1) |
|
Calling hare.buildWall() to Build a Wall |
|
|
140 | (1) |
|
Bonus Activity: mylabel Program with Command Line Arguments |
|
|
141 | (1) |
|
|
141 | (2) |
12 Constructing Rooms |
|
143 | (10) |
|
Designing a Room-Building Algorithm |
|
|
144 | (1) |
|
Extending the hare Module |
|
|
145 | (1) |
|
Calculating the Total Number of Blocks Needed to Build a Room |
|
|
146 | (1) |
|
Writing the buildRoom() Function |
|
|
147 | (2) |
|
Writing the buildroom Program |
|
|
149 | (1) |
|
Running the buildroom Program |
|
|
150 | (1) |
|
Bonus Activity: Plus-Shaped Rooms |
|
|
151 | (1) |
|
|
151 | (2) |
13 Constructing Floors |
|
153 | (20) |
|
Designing the Sweeping Algorithm |
|
|
154 | (4) |
|
|
155 | (2) |
|
Returning to the Starting Position |
|
|
157 | (1) |
|
Passing Functions to Functions |
|
|
158 | (2) |
|
Extending the hare Module |
|
|
160 | (1) |
|
Calling the sweepFunc() Function |
|
|
161 | (4) |
|
Moving Along the Rows and Columns |
|
|
162 | (1) |
|
Figuring Out If a Number Is Even or Odd with the Modulus Operator |
|
|
163 | (1) |
|
The Even-Width and Odd-Width Paths |
|
|
164 | (1) |
|
Writing the buildFloor() Function |
|
|
165 | (1) |
|
Writing the buildfloor Program |
|
|
165 | (1) |
|
Running the buildfloor Program |
|
|
166 | (1) |
|
Creating a Patterned Floor |
|
|
166 | (5) |
|
Writing the buildcheckerboard Program |
|
|
167 | (1) |
|
Running the buildcheckerboard Program |
|
|
168 | (1) |
|
Writing the placeCheckerboard() Function |
|
|
169 | (1) |
|
Calling the sweepField() Function |
|
|
170 | (11) |
|
Bonus Activity: Different-Colored Checkerboards |
|
|
171 | (1) |
|
|
171 | (2) |
14 Programming A Robotic Farm |
|
173 | (18) |
|
|
174 | (1) |
|
Designing the Wheat-Farming Algorithm |
|
|
175 | (1) |
|
Extending the hare Module |
|
|
176 | (1) |
|
Writing the farmwheat Program |
|
|
177 | (2) |
|
Running the farmwheat Program |
|
|
179 | (1) |
|
Setup for the farmwheat Program |
|
|
180 | (1) |
|
Writing Functions to Use in the Main Program |
|
|
181 | (3) |
|
|
181 | (1) |
|
|
182 | (1) |
|
|
183 | (1) |
|
|
184 | (2) |
|
Bonus Activity: Giant Wheat Fields |
|
|
186 | (1) |
|
Tips for Automating Other Kinds of Farming |
|
|
186 | (4) |
|
|
186 | (1) |
|
Milking Cows and Shearing Sheep |
|
|
187 | (1) |
|
|
188 | (1) |
|
Farming Cacti and Sugar Cane |
|
|
189 | (1) |
|
|
190 | (1) |
15 Programming A Staircase Miner |
|
191 | (18) |
|
Designing the Stair-Mining Algorithm |
|
|
193 | (4) |
|
Extending the hare Module |
|
|
197 | (1) |
|
Writing the digUntilClear() and digUpUntilClear() Functions |
|
|
198 | (1) |
|
Writing the stairminer Program |
|
|
199 | (1) |
|
Running the stairminer Program |
|
|
200 | (1) |
|
Setup for the stairminer Program |
|
|
201 | (1) |
|
Creating the First Stair Step |
|
|
201 | (1) |
|
|
202 | (2) |
|
Checking the Turtle&aposs Fuel |
|
|
204 | (2) |
|
Checking the Turtle&aposs Inventory |
|
|
206 | (1) |
|
|
206 | (1) |
|
Bonus Activity: Tall Tunnel |
|
|
207 | (1) |
|
|
207 | (2) |
Function Reference |
|
209 | (8) |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
211 | (1) |
|
|
211 | (1) |
|
os (Operating System) API |
|
|
211 | (1) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
212 | (4) |
|
|
213 | (1) |
|
|
213 | (1) |
|
|
214 | (1) |
|
|
215 | (1) |
|
|
215 | (1) |
|
|
216 | (1) |
|
|
216 | (1) |
Name ID Reference |
|
217 | (10) |
|
Finding a Block&aposs Name ID |
|
|
217 | (1) |
|
Distinguishing Between Blocks That Share Name IDs |
|
|
218 | (1) |
|
|
219 | (8) |
Index |
|
227 | |