Getting Started (ComputerCraft)/de


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

Introduction
 consists primarily of three major components; the, s, and the 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 ComputerCraft. 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. 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 brings up the CraftOS command line (CraftOS is the default operating system for s); it's from here where most users run programs on their s.

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. Note that parameters in italics are considered optional.

{| class="wikitable" width="100%" ! command/command alias ! 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
 * 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
 * mv/move/rename
 * mv/move/rename

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...

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 and write functions.

Open a new program file in the editor (recommended name: hello2). Enter the following in...

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

The print function in this example concentrates the multiple arguments( ie  is the same as  this example shows how to create a program, how to simply print information to the screen, simply reading input, and storing data in a variable.

Computer Light Switch
This example requires a little more setup than just the basic. To the left of the computer, place either some redstone or (only one block is needed). Next to that, place a lamp (it doesn't matter which type). Please note one can place this setup on any side of the computer, however, the will affect how the code needs to be written (it is pretty self explanatory, though).

In this example, quite a few new functions/statements are introduced including the while loop, if...then...else statements, os.pullEvent, print which is, redstone.setOutput, and comments (for ease of navigating/identifying sections of code). comments are the text that is after a

Enter the following code (feel free to omit comments, they are there for ease of reading the code but it's understandable if one feels it's a bit much to type in)...

Running this code will show something like the following on the screen... To turn lamp on, press L. To exit, press any other key.

(Assuming user presses L, the lamp turns on and the following shows up...)

To turn lamp off, press L. To exit, press any other key.

Pressing any other key will return the user to the CraftOS prompt. This program looks complicated, but in reality it's just very messy (and actually violating a few conventions). However, writing this code shows the user the essence of what is happening and sets one up for the next example.

Computer Light Switch Mk. II
This example will use the setup from the previous example. Here, the user will learn to use functions as well as other aspects of the Redstone API to control the lamp and avoid "bulky" code. It is recommended to start a new program file rather than editing the old one (due to the way the CraftOS editor works). For simplicity I will omit most of the previous comments to allow the code to be seen easier. this program uses a new part of the redstone API, redstone.getOutput(side), this allows the computer to read if the computer is powering redstone or not, and takes only one argument, side.

Smart Computer Light Switch
Content coming.

Was tun, wenn etwas nicht funktioniert
Es wird passieren, einmal akribisch verbringen nur das Schreiben von Code, um zu speichern und führen ihr Programm zu finden ... es wird nicht funktionieren. Normalerweise gibt es ein paar wichtige Dinge zu werfen, bevor Sie die Maus an der nächstgelegenen unschuldiger Zuschauer zu überprüfen ...


 * 1) Prüfen Sie die Fehlermeldung ... 99,999 % der Zeit wird es ein, wo genau der Fehler gemacht wurde ( falsche Syntax , fehlende End-Statement , etc.) zu erzählen.
 * 2) Prüfen Sie den Einsatz von Fall ( Groß-und Kleinbuchstaben ) . Denken Sie daran, die Funktionen sind in der Regel mit einem Kleinbuchstaben beginnen, aber zusätzliche "Worte" wird in Großbuchstaben in sich haben (zum Beispiel - . Redstone  ' s  et  ' O  utput ).
 * 3) Prüfen Steueranweisungen ( while, for, wenn, etc). Stellen Sie sicher, dass sie richtig und korrekt beendet erklärt (manchmal auch eine fehlende Ende -Anweisung nicht für einige Linien registrieren ).
 * 4) Wenn Sie Zweifel haben, schreiben Sie es heraus. Man kann manchmal überrascht, wie grell ein Fehler ist, wenn etwas umgeschrieben werden ... trotz fehlender es das erste Mal.
 * 5) Stellen Sie die [ http://forum.feed-the-beast.com Gemeinschaft] . Manchmal sind die Dinge schwieriger, als sie zu sein scheinen aber die Chancen sind, jemand hat den gleichen Fehler gemacht und herausgefunden , aber es gibt auch eine gute Chance, dass mit einem anderen Paar Augen auf das Problem jeder kann lernen, wie man es zu tun ... vielleicht sogar einen besseren Weg ! Denken Sie daran , das Forum nach bisherigen Beiträge , bevor sie einen neuen Thread zu suchen.