Getting Started (ComputerCraft)

''Please note that this guide is very much a WiP (Work in Progress) at this time. Please PM CoderJ on the forums with any comments or corrections''

Introduction
ComputerCraft consists primarily of three major components; the Computer, Turtles, and the Peripherals that attach to both to extend their basic functionality. It is possible to craft all three without ever writing an actual program, just using the built-in programs provided by the mod... but by doing so one ignores the true potential of ComputeCraft. This guide assumes that the user has no to little experience with Lua, the programming language used by ComputerCraft and will give some basics as it progresses. Please also note that this guide is only going to touch on some of the basic concepts and components of ComputerCraft; additional information can be found at ComputerCraft's Official Site as well as throughout this wiki and guides that will come at later dates.

The Computer
The first and most basic component of ComputerCraft is the Computer. The recipe is fairly inexpensive and can be made relatively early if one lucks out finding redstone. The computer may be placed down wherever the player likes and can be picked up again by breaking it with any tool.

Right-clicking on the Computer brings up the CraftOS command line (CraftOS is the default operating system for computers); it's from here where most users run programs on their computers.

Basic CraftOS Commands
The basic commands used in CraftOS are, for the most part, either identical or very similar to the basic commands used in nearly all distributions of *nix operating systems; as such, most users (even those who have only occasionally used a command line in other OS's, such as Windows or OSX) should be familiar or easily able to become familiar with them. All commands are run from the CraftOS command line and are given in the following format...
 * command/command alias (if any)  
 * Command description/use


 * help  
 * On it's own, returns a list of help topics. Specifying the topic after the command returns information on that topic.


 * programs
 * Lists the available programs to be run.


 * apis
 * Returns a list of available APIs (application programming interfaces) that one can use (via Lua) from within CraftOS. More information on various APIs can be obtained by typing using the help command followed by the API name.


 * ls/list  
 * Lists the contents of a directory; if no directory is given lists the contents of the current one.


 * cd
 * Changes the current directory, .. can be used to go to the parent directory of where the command is issued.


 * mkdir
 * Creates a new directory with the given name


 * mv/move/rename
 * If used without a directory path in the destination, renames the file; otherwise will move and rename the file.


 * edit
 * Opens a simple text editor to edit the file named; if the file doesn't exist, it will be created when the contents are saved. Pressing ctrl will switch to the command menu, where one can save or exit the editor.


 * reboot
 * Restarts 'CraftOS.

There are many more commands, but one can easily read up on those by using the help command.

Programming
To start a new program, simply type edit followed by a file name. This guide will start with the first two obvious programs to get the user's feet wet, but will quickly move to specific examples that apply to CraftOS and ComputerCraft's interaction with other objects in the world. Functions and API methods used in examples will have links that will explain them further.

Hello World
The traditional first step in almost any programming language is learning how to output a simple line of text (usually "Hello world.") to the screen. This example will show the reader how to do that via basic use of the print function.

Open a new program file in the editor (recommended name: hello), and type the following in... print("Hello world.")

Simple, right? Save the file and exit the editor, then type in the name of the program. All going well, the following will appear in the CraftOS window... > hello Hello world. >

Congratulations on taking the first step in any programming language. Although only one line, this program demonstrates how to output text to the window. This is usually the primary way to return information to a user (aside from graphics, which are beyond the scope of this guide).

Hello Username
While outputting text is important, it is also important to receive input (whether it is information to be used by the program or navigation through a program's interface). This program will expand upon the print function, as well as introduce variables and the read function.

Open a new program file in the editor (recommended name: hello2). Enter the following in... print("Please enter your name: ") local username = read print("Hello ", username, ".")

Save and exit the editor, then execute the program. It will expect some input from the user, but should overall look like this...

>hello2 Please enter your name: CoderJ Hello CoderJ. >

Computer Light Switch
Content coming.

Computer Light Switch
Content coming.

Whole House Lighting Control
Content coming.

Advanced Examples
Content coming.