This is a WIP (Work In Progress) It might not be done yet :)/> Suggest what I should do next!
Here, I will be explaining a few things. How to get around in your computer, some syntax, how to make files and edit them, and more :)/> Lets start.
Getting Around in CC.
We will be learning:
- How to move around programs in CC
- How to make a computer
- How to look at how many programs you have
- How to edit programs
Getting around in computercraft can be quite simple. After making a computer, using this recipe (s = stone, r = redstone, g = glass panes):
s s s
s r s
s g s
Place it down and open it up. Let's get started! First, type
> ls
(LS). This will bring up all the programs that are in your computer currently. If you are just making a new computer, all you will see is "rom". You must be wondering, what is this rom you speak of? Well, let's find out. Type
> cd rom
it will look somewhat like the above code. this brings you into another folder! Congrats, you entered your first folder. Now if you type ls again, you see there are more programs! Lets try opening a file. Type
> edit startup
(This is really important ^^^, you will use it to create programs with ease later on, so remember it!)
This will bring you to a file. You are now editing your first file! This is where the magic happens, where you code all your stuff! This file that you are in will do what you program it to do every time you turn on your computer. To exit your file, press ctrl (usually found in the bottom left corner) and press right on your arrow keys once. Press enter. You should be in the rom folder again. One useful little tool is the previous tool. you can type
> cd ..
and it will bring you to the previous page (our home page, if you will). This is a lot to take in, and only the basics. I covered a lot, but might cover more later in the tutorial. That is it for navigating!
Basic Syntax - Printing, Math, Running a program
We will be learning:
- How to print stuff to a computer
- How to do math with a computer
- How to run a program
Now that you know how to look around in your computer, let's create our first program! Go ahead and open up your computer. Once you get there, let's make a program. Remember that edit command we used earlier? This is where it comes in handy! Go ahead and think of a name for your program. My program name is going to be "math". Go ahead and make yours anything you like.
> edit math
This will make a program called math, and put us inside it! Now, let's put some code in there. We have all been in 1st grade right? This should be easy then! We all know that an addition problem is written using two numbers and a plus sign, right? Well, go ahead and do that! My program looks like:
1+1
Oh wait, that won't work! We have to learn about the print syntax! This is simple. Look at it this way: Your computer likes to interact with you. It wants to talk with you, but has no mouth! So in order to talk with you, it needs to write it out. That is what it does with print! It returns what you said in the program. So lets try this out. The syntax for print looks like:
print()
Yep. That easy. Now, I know you are excited to run your first program. Wait wait, but if you run it now, it doesnt know what to do! You need to give it words to say. Well, your computer has gone through all those grades of math, so it understands 1+1! Lets try it now!
print(1+1)
Your code should look similar to mine. Now to try it out. Press ctrl again and press enter. This saves your program, so you dont lose it! Now press ctrl again and press right once, so you are hovering over exit, and press enter. You are now at the homepage. To run a program, simply type
> programnamehere
So for me it would look like
> math
Ok, so what did I get…. 2! Computers grow up so fast… Well, while I go and tear up in a corner, you mess around with your newly found program! It knows all kinds of math!
print(1+1)
print(1-1)
print(1*1)
print(1/1)
Those all work :)/> So have fun, and see you in the next part!
Basic Syntax 2 - Variables, Strings.
We will be learning:
- Variables
- How to print variables
- Strings
So. You are excited for our next lesson? Well, here it is! We are gonna learn variables! Get started by opening your computer and making a new program. You remember how to do that right? Well, if you dont, go back to the previous lesson :)/> Make a new program, and name it anything you like. My program will be named variable. Start by declaring some variables. Variables are things that you can store things in. Think of a variable like a bank. You have multiple different banks, and you store your stuff in there, but only numbers and strings, no money. And no, I dont mean a piece of string, I mean a string! Most of our things we want the computer to say using print will use strings! Strings go in quotation marks, like this:
print("Hello World!")
Now that we have that handeled, lets declare a variable! My variable will be called myVariable.
local myVariable = 10
This is what the syntax for a variable looks like! The stuff after the = sign is the stuff that will be stored in the variable. I used a number, but you can use our newly learned strings. Remember to use quotation marks! So now that we have a variable, lets make the computer say our variable! Do you know how to do this? Well, it looks like this!
print(YourVariableNameHere)
So for me it would be
print(myVariable)
Now run your code and see what happens! The stuff you stored in the variable should show up! Pretty cool, right? That is all for this lesson, see you in the next one!
Basic Syntax 3 - Booleans, If statements.
We will be learning:
- If Statement Syntax
- Booleans
- Operators
local myVariable = true
local yourVariable = false
if then
end
Altogether, you should have what I have above. Now I will introduce my best friends, operators! The two operators we are using today are the or and the and operators. It is easy to do this, all you need is a little help. What we can do is check our variables to see if they are true or false! Let's try it out!
local myVariable = true
local yourVariable = false
if myVariable and yourVariable then --This means if myVariable and yourVariable are both true, then run the if statement.
print("We are both true!")
elseif myVariable or yourVariable then --If they arent both true then check if either of them are true
print("One of us is true!")
else --When all else fails, do this code.
print("We are both false :(/>/>/>/>/>/>")
end
Now run your code. If you followed my code, you should get a message from the computer saying "One of us is true!" Mess around with the variables a bit, switch the booleans and see what happens.
Basic Syntax 4 - For Loops.
Hello! It's been a while! Time for some more learning. We have for loops now, this is gonna be fun! This is a little similar to if statements. Lets take a look.
local var hello = true
for hello do
print("Hello!")
hello = false
end
Now, as the header says, this is a loop. Whenever hello is true, print Hello!, and then set it false. But of course, you don't have to set it to false in that statement, for then it only runs once! You can just make the variable hello false somewhere else. For example:
local var IAmTrue = true
local var IAmFalse = false
for IAmTrue = true do
print("I am true!")
IAmFalse = true
end
for IAmFalse do
print("Now I am true!")
IAmTrue = false
end
That's all! See you next time!
Basic Syntax 5 - User Input
Wow, it's been a while since I wrote one of these! Lets see, where did we leave off… Oh yes! For loops… Now we should do user input. Lets get started!
print("Enter your name: ")
local input = read()
print("Your name is ", input, "!")
Woah, this is new… Lets see… So we make a new local variable named input, and set it to read(). Then we print "Enter your name", they enter their name, and then it prints: "Your name is (name here)!"