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.

Die Computer
Die erste und grundlegende Komponente von ComputerCraft ist der. Das Rezept ist verhältnismäßig billig und kann relativ früh, falls man über Redstone verfügt, hergestellt werden. Der Computer kann überall plaziert und durch Zerstören mit einem beliebigen Werkzeug wieder aufgenommen werden.

Rechtsklick auf den öfnet die CraftOS Befehlszeile (CraftOS ist das Standardbetriebssystem der  ), von hier aus werden die meisten Programme auf dem  ausgeführt.

Grundlegende CraftOS Befehle
Die grundlegenden Befehle die im CraftOS verwendet werden sind zum größten Teil entweder identisch oder sehr ähnlich zu den grundlegenden Befehle die in fast allen Distributionen von *nix-Betriebssystemen verwendet werden; ansonsten sollten diejenigen Nutzer die mit Progammiersprachen grundlegend vertraut sind (Auch die die nur gelegentlich eine Befehlszeile in andere Betriebssystemen, wie Windows oder OSX verwendet haben) leicht in der Lage sein, sich mit ihnen vertraut zu machen. Die folgenden Befehle laufen vom CraftOS aus. Es ist zu beachten, dass Parameter in  kursiv als optional angesehen werden.

{| class="wikitable" width="100%" ! command/command alias ! Command description/use
 * help  
 * On its 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:

Herzlichen Glückwunsch zum ersten Schritt in einer beliebigen Programmiersprache. Obwohl nur ein paar Zeilen lang, zeigt das Programm, wie die Ausgabe von Text funktioniert. Dies ist in der Regel der erste Weg, um Informationen zu dem Benutzer des Computers (abgesehen von Grafiken, diese werden in diesem Handbuch nicht behandelt) auszugeben.

Hallo Benutzername
Während die Ausgabe von Text wichtig ist, ist es auch wichtig, Eingaben (ob es nun Informationen, die von einem Programm werwendet werden, oder Navigationen durch ein Programmschnittstelle sind) zu erhalten. Dieses Programm wird von der print Funktion aus fortfahren, sowie Variablen und die read und [http:// computercraft.info/wiki/Write write ] Funktionen vorstellen.

Öffnen Sie eine neue Programmdatei im Editor (empfohlener Name: hallo2). Geben Sie Folgendes ein...

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

 (Vorausgesetzt der Benutzer drückt L, schaltet sich die Lampe an und das folgende wird angezeigt, ...)

Zum Auschalten der Lampe, drücken Sie L. Zum Beenden, drücken Sie eine beliebige andere Taste.

Durch drücken einer beliebigen anderen Taste, wird der Benutzer auf die CraftOS Eingabeaufforderung zurückzukehren. Dieses Programm sieht kompliziert aus, aber in Wirklichkeit ist es nur sehr chaotisch (und verletzt tatsächlich ein paar Konventionen). Das Schreibe dieses Codes zeigt jedoch dem Benutzer die Essenz dessen, was geschieht, und stellt den Benutzer auf das nächste Beispiel ein.

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), which allows the computer to read whether the computer is powering redstone or not, and takes only one argument: side.

The set of If statements can be simplified to:

Intelligenten Computerlichtschalter
"Inhalt kommenden"

What To Do When Things Don't Work
It will happen; one will spend time meticulously writing code only to save and run their program to find...it won't work. There's usually a few important things to check before throwing the mouse at the nearest innocent bystander...


 * 1) Check the error message... 99.999% of the time it will tell one exactly where the mistake was made (improper syntax, missing end statement, etc).
 * 2) Check the use of case (upper and lower case letters). Remember, functions usually start with a lower case letter but additional 'words' will have upper case in them (for example - redstone.setOutput).
 * 3) Check control statements (while, for, if, etc). Make sure they're declared right and terminated correctly (sometimes a missing end statement won't register for quite a few lines).
 * 4) When in doubt, write it out. One can sometimes be surprised how glaring an error is when rewriting something...despite missing it the first time.
 * 5) Ask the Community. Sometimes things are trickier than they appear to be but chances are someone has made the same mistake and figured it out, however, there's also a good chance that with another pair of eyes on the problem everyone can learn how to do it... maybe even find a better way! Just remember to search the forums for previous posts before making a new thread.