This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BigSHinyToys's profile picture

Computer Craft Tips and Tricks

Started by BigSHinyToys, 21 June 2012 - 04:05 PM
BigSHinyToys #1
Posted 21 June 2012 - 06:05 PM
Ok so you have seen some cool vids of CC (Computer Craft) doing some amazing stuff and finally decided to try it. you have followed all the correct steps and are now standing in front of a CC computer staring at the blackness wondering how to use it… well this is the thread for you.

CC's Editor/My First Program

So enough chit chat lets start. Your fist program will be simple and a tradition one.
walk over to the computer and (Right Click) using your mouse on the computer.
you will now be looking at this.

Craft OS 1.3
> _
step two open the editor
to open the editor type in

Craft OS 1.3
>  edit helloworld_
and press enter. You have just opened the editor and created are about to create a file/program called helloworld. type in

print("Hello World")
you should notice the test at the bottom of the page. press Ctrl now. Two options come up, we want to save so press enter. Now we want to exit so use the arrow keys to change the option selected and press enter again.

You are back at a screen seing the > _ again. type in

helloworld
press enter.

The screen should now look like this.

> helloworld
Hello World
> _


PRO tip
press escape [Esc] to leave the terminal
Congratulations you have just created your first program in CC
Exercices
1 ) edit the program we just made Hint: it is the same as making a new program
2 ) change the test to say your name
3 ) make another program that says something else.

What the hell is a function??

A function is section of code we call with a name you should be family with one already " print() "
functions are used for almost all tasks in CC we can even make our own. for now we will use a simple one.place a piece of redstone wire behind your computer. Now lets turn it on.
make a new program call it what ever you like.
make its content be

redstone.setOutput("back",true)
sleep(3)
redstone.setOutput("back",false)
run this code leave the terminal and look at the wire for at least 10 seconds. it turns on the off 10 seconds latter.
Now to break down our code and explain what just happened.

redstone.setOutput("back",true)
this is a function this function activates redstone and can deactivate redstone.
the setOutput part is so we can "set" (make the computer change) its "Output"
"back" is to tell the computer what site to change and true is a boolean vale that tells it to come on.

WHY is there " " around the back but not the true ??

back is a string and true is a boolean strings hold words example
"Hello World"
"back"
"left"
"true"
boolean are not string so no "" are needed there are two boolean values
true
false

there is a Variables specific to show the absence of other variables called nil

Both string's and booleans are Variables.

The sleep() tells the computer to wait for the time specified in the brackets.

Why is there no "" on the number?

Numbers are called (double-precision floating-point) these are also variables. (double-precision floating-point) need no "" marks around them.
why is there a , between "back" and true. A function can take in more that one variable each is separate by a , . Some functions need no variables like term.clear() others require one some two or more. to find more information on what functions exist in CC type in

help index
all the names that come up are able to be opened by typing help and its name eg

help redstone
Exercises

Find out what term.clear() does and look up help term

Key Combos

say you made a program and it so doing somthing you dont want it to how do you stop it. You use keybord shortcuts.

Pressing Crtl and T at the same time will stop the program you are running and return you to the command interface.
Pressing Ctrl and S will shutdown your computer
Pressing Ctrl and R will reboot a computer


Section 2 Common questions
Why does the computer reboot when i leave and return to a world?

Computers in Computer craft dont rember where they were in a program so restart insted. This can be worked around By naming your program "startup" with no "" around it. the startup file can be on a disk or on a computer's root directory

how do I disable Ctrl+T Crtl+R and Crtl+S ?
there is no way to disbale Crtl+R or Crtl+S you can disable Crtl+T thought. to do this you must over ride a function (sounds scaryer than it is)

simple put this at the top of your program

local OldEvent = os.pullEvent -- copys old osEvent so we back it up
os.pullEvent = os.pullEventRaw -- this removes Crtl + t I will not go into how just trust me

and have it do this before it closes

os.pullEvent = OldEvent -- we have to do this to reenable Ctrl+T before retuning to command interface

More to come stay tuned.

If this was helpfull or there are any mistakes in the above material or you would like to contribute please post bellow.
MysticT #2
Posted 21 June 2012 - 06:17 PM
there are three boolean values
true
false
nil
nil is not a boolean, it's type is nil. From the lua manual:
Nil is the type of the value nil, whose main property is to be different from any other value; it usually represents the absence of a useful value.
But unlike any other value, it evaluates to false:
Both nil and false make a condition false; any other value makes it true.


Numbers are called integers , int for short these are also variables.
Lua numbers are not integers. From the lua manual:
Number represents real (double-precision floating-point) numbers.
BigSHinyToys #3
Posted 21 June 2012 - 06:29 PM
corrections made new information learned. Thanks MysticT