Getting Started (ComputerCraft)/it


 * 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

Introduzione
 consiste per la maggior parte in tre elementi fondamentali; il, le s, e le che possono essere collegate ad entrambi i macchinari per estendere le loro funzionailità. E' possibile crfatare tutti e tre i macchinari senza dover scrivere nessun programma, ma usando i programmi preinstallti nella mod... ma in questo modo rinuncerai alle possibilità migliori offerte da ComputerCraft. Questa guida tiene in considerazione che l'utente non abbia nessuna, o poco, conoscenza del linguaggio Lua, il linguaggio di programmazione usato da ComputerCraft e mostrerà alcune delle basi su cui iniziare. Da notare che questa guida coprirà solo i concetti base ed i componenti basilari di ComputerCraft; ulteriori e più dettagliate informazioni si possono visionare sul sito ComputerCraft's Official Site.

Il Computer
Il primo e basilare macchinario di ComputerCraft è il. La ricetta è molto semplice, ed è quindi possibile craftarlo anche ad inizio gioco se si ha la fortuna di trovare della Redstone. Il computer può essere posizionato ovunque e lo si può riprendere colpendolo con qualsiasi attrezzo.

Cliccando con il pulsante destr sul farà apparire sullo schermo la linea di comando CraftOS (CraftOS è il sistema operativo di default dei s); è da qui che il giocatore potrà avviare i programmi nei.

Comandi base di CraftOS
I comandi base usati in CraftOS sono, per la maggior parte,uguali se non molto simili ai comandi di base usati in più o meno tutti i sistemi operativi *nix ; per cui, molti utentis (persino quelli che hanno occasianalmente usato il "prompt dei comandi" nel loro OS's, come in Windows or OSX) dovrebbero sentirsi fiduciosi enll'utilizzarli. Tutti i comandi partono in CraftOS. Da tenere conto che le scritte italics(in corsivo) sono da considerarsi opzionali

Lista dei comandi: {| class="wikitable" width="100%" ! command/command alias ! Command description/use
 * help  
 * Se inserità ci darà una lista di aiuto per i comandi, se si aggiunge il nome del topic ci darà invece una lista dei comandi di aiuto per il topic specificato.
 * programs
 * La lista dei programmi che possiamo avviare.
 * apis
 * Ci mostrerà la lista delle APIs (application programming interfaces) che posso essere usate con (Lua) dal CraftOS. Informazioni dettagliate sulle varie APIs possono essere mostrate inserendo il comando help seguito dal nome della API.
 * ls/list  
 * Mostra i contenuti della directory; se nessuna directory viene specificata mostyrerà i contenuti dell'attuale directory.
 * cd
 * Cambia la directory, .. può essere utilizzato per accedere alla directory principale di cui viene usato il comando.
 * mkdir
 * Crea una nuova directory e le si da un nome.
 * mv/move/rename
 * cd
 * Cambia la directory, .. può essere utilizzato per accedere alla directory principale di cui viene usato il comando.
 * mkdir
 * Crea una nuova directory e le si da un nome.
 * 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.

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