Jump to content




Computer Basics I


15 replies to this topic

#1 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 01 September 2013 - 03:27 AM

This is a tutorial in the Ask a Pro Renewal Project series.

This tutorial has no prerequisite tutorials.

Next suggested tutorial:
Computer Basics II

In this tutorial, we will craft our first computer or turtle, explore the command line and lua prompt, create a startup file, and learn the cd and list commands. To begin, you will need a copy of Minecraft with the appropriate version of ComputerCraft installed.

To craft a computer, you will need seven smooth stone, one redstone dust, and one glass pane. Arrange these items in the crafting grid like so:

Posted Image

Note that you can replace the smooth stone with gold ingots to craft an advanced computer, which adds a colored screen and mouse support. Once a computer is crafted, it cannot be upgraded into an advanced computer. Select your new computer and place it in the world like any other block. Right-click on any side of the computer block to open the computer's interface. You should see a black rectangle with a grey (or gold) border with some text in the upper-left corner, like this:

Posted Image

This is called the terminal or command line interface. We can type into this and the computer will receive the keystrokes. Let's type in `list` and hit the Enter key. We'll see the four letters appear on the screen as we type them, and when we hit Enter, the computer will try to run the "list" program. It's a valid program, so we will get to see the output it prints, which looks something like this:

Posted Image

The list program shows the files and folders in the current directory. If we are using an advanced computer, the folders' names will be colored lime green, while the file names are white. On a normal computer, the files' and folders' names are all in white, of course. As you can see, we only have a folder named "rom" on this computer. The rom folder is present on all computers. It is also read-only, which means that you cannot make any changes to any files or folders in it, or add any new files or folders to it.

Let's see what's inside the rom folder. The first way to figure out what's inside the rom folder is simply to tell the list program to show the contents of that folder instead of the current folder. We can run "list" again, but this time give it an argument telling it a specific folder to show the contents of. Many of the programs in ComputerCraft accept arguments to change their behavior, and some require them to work at all. Type in `list rom` to show the contents of the rom folder:

Posted Image

Now we can see the contents of the rom folder. But there's another way to get there which can be handy at times. We can change our current directory with the "cd" (change directory) program. Since we're in the main folder (or root) of the computer's drive, we type `cd rom` to change our current directory to the rom folder:

Posted Image

Now our prompt looks a little different. It's been hard to tell so far, but the prompt has been showing us our current directory all along. Now that our current directory is the rom folder, it has changed to "rom>". Now if we type `list` again, with no arguments, it will show us the current directory's contents. Now that the current directory is the rom folder, it will show us the same results as when we ran `list rom` earlier.

Posted Image

We can return to the main folder of the computer by using the `cd ..` command. Running `cd ..` always changes the directory to be one level higher than the current directory, if possible. If our current directory was /rom/programs, running `cd ..` would change our current directory to be /rom. Running it again would change our current directory to be the main directory. Let's go ahead and run `cd ..` now:

Posted Image

Note that our prompt has gone back to being just ">", since we are back at the root of the drive. Feel free to play around with navigating through the directories a little bit to familiarize yourself with these two commands. There is one way to get yourself into trouble with the cd command, so I'll demonstrate that problem. In this example, we've changed our current directory to /rom/help:

Posted Image

We try to use `cd ..` to get out of this folder to keep exploring, but wait, what?

Posted Image

An error message?! Why did the cd program suddenly break? Well, the answer is that the help directory contains a bunch of plain-text help files to provide information on each of the programs that ComputerCraft comes with. The shell program that creates the command-line interface that we are using looks for the programs that we tell it to run in the current directory first. Since there is a file named "cd" in the /rom/help directory, which is our current directory, it tries to run that file. But that file is just a plain text help file, so when it tries to run it as a program, it just throws an error and stops!

To fix the problem, we have to tell the shell exactly which "cd" program to try to run, so that it won't try to run the help file for cd instead. The cd program is actually located at /rom/programs/cd, so we type in `/rom/programs/cd ..` to escape the help directory.

Posted Image

Let's move on to the Lua prompt. The "lua" program starts another command-line interface, but this one is a little different than the shell. In the Lua prompt, we can run little bits of actual lua code directly, instead of running program files with Lua in them like the shell does. Type `cd /` to change to the root directory directly, then type `lua` to start the Lua prompt.

Posted Image

You should see a screen a little like this one. Take note of the "Call exit() to exit." line. We'll run a couple of simple lua lines, then use the exit() function to exit the lua prompt. Type in `x = 1 + 1` and hit Enter. The prompt will accept the line and prompt you for another. Type `x`, and the value of the variable (2) should be printed on the next line, something like this:

Posted Image

Type `exit()` to quit the Lua prompt when you're ready. We're back to our familiar command-line. Let's create a startup file next. When a computer is booted up, it will run the Lua code in its startup file. This is commonly used to run a program that you want the computer to do each time it starts, like a door lock program. Type `edit startup` to open the editor. We're starting up the edit program with "startup" as its argument. This tells the edit program that we want to edit the file named "startup" in the current directory. Since that file doesn't exist, it will open up a blank editor. When we save the file in the editor, it will automatically create the file since it did not exist already. The edit program is one of the programs in ComputerCraft that requires an argument when you start it so that it knows what file you're wanting to edit.

Posted Image

We have a blank file, since this is a new computer. Let's make it display a line of text using the print() function. We add `print("Hello, World!")` to the file. To save the file, we hit Ctrl like it says on the bottom line of the screen (on some keyboards, this will be AltGr or another key). A small menu pops up on the bottom line. We can either hit Enter or the S key to save the file. The bottom line will change to "Saved as startup" if all went well:

Posted Image

Now we hit Ctrl again to bring up the menu, and either hit the E key to exit, or use the right arrow key to select Exit and hit Enter. We've now created a startup file and are back to the command line prompt. Let's reboot the computer to see what our startup file will have changed. Type `reboot` and hit Enter. The computer will reboot, and when it comes up, there's our printed line!

Posted Image

In this tutorial, we learned how to create a computer in ComputerCraft. We learned how to use the shell and lua prompts to run programs or bits of lua code. We learned how to use two of the programs ComputerCraft comes with, cd and list. We know how to create, edit and save files in the edit program, and we have learned what the startup file is and does. Thanks for reading!

#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 01 September 2013 - 03:47 AM

My friend is reading this, and he has never used CC before! This is a very nice tutorial for beginners. (On behalf of my friend, thanks!)

#3 BigSHinyToys

  • Members
  • 1,001 posts

Posted 02 September 2013 - 07:22 AM

Some of the image links are not working ? Is anyone else having this problem?

#4 Symmetryc

  • Members
  • 434 posts

Posted 02 September 2013 - 08:11 AM

View PostBigSHinyToys, on 02 September 2013 - 07:22 AM, said:

Some of the image links are not working ? Is anyone else having this problem?
Yeah, some of them are showing up with some photo error looking thing.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 September 2013 - 05:52 PM

I haven't had any issues with the images. Try doing a forced reload of the page or clearing your cache and let me know if that resolves it. If not, I may have to look into alternate image hosting solutions.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 September 2013 - 05:55 PM

View PostLyqyd, on 02 September 2013 - 05:52 PM, said:

I haven't had any issues with the images. Try doing a forced reload of the page or clearing your cache and let me know if that resolves it. If not, I may have to look into alternate image hosting solutions.
I've got the "The image you are requesting does not exist or is no longer available." image from imgur coming up in place of:
  • `list rom`
  • `cd /rom/help`
  • `cd ..` bug


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 September 2013 - 01:04 AM

Okay, those three images had somehow disappeared from the album. I've re-uploaded them, so let me know if there are any further issues with the images.

#8 ATMunn

  • Members
  • 62 posts
  • LocationSomewhere on this earth.

Posted 16 October 2013 - 08:28 PM

Lyqyd, I know this isn't related to the tutorial, but I need to ask you something.
I just got my computer craft forums account today, so I can't post a new topic. The reason why this is a problem is: I want to post a new tutorial, but can't, because I can't post a new topic. Can you help me?

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 October 2013 - 08:32 PM

View PostATMunn, on 16 October 2013 - 08:28 PM, said:

Lyqyd, I know this isn't related to the tutorial, but I need to ask you something.
I just got my computer craft forums account today, so I can't post a new topic. The reason why this is a problem is: I want to post a new tutorial, but can't, because I can't post a new topic. Can you help me?
You should learn to read stickies. Especially the forum rules sticky which is global, so it's everywhere! There you will find your answer.

#10 ATMunn

  • Members
  • 62 posts
  • LocationSomewhere on this earth.

Posted 17 October 2013 - 12:45 PM

I have no idea what a sticky is.

#11 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 October 2013 - 01:28 PM

Sticky (or pinned) posts always appear at the top of the topic list, with other topics listed below them. Announcements, like the Forum Guidelines announcement you should have read before posting anything, appear above the topic list.

#12 ATMunn

  • Members
  • 62 posts
  • LocationSomewhere on this earth.

Posted 18 October 2013 - 03:09 PM

Nevermind, I can post topics now :D

#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 18 October 2013 - 03:33 PM

View PostATMunn, on 18 October 2013 - 03:09 PM, said:

Nevermind, I can post topics now :D
No, don't just "nevermind" you need to read the forum rules, or it could potentially get you on the ban list very quickly. it's always a good idea to know exactly what the rules are when you're on forums!

#14 Kristopher_Jones

  • Members
  • 16 posts
  • LocationLatvia

Posted 29 October 2015 - 03:37 PM

Thank you!

#15 muralimude

  • New Members
  • 1 posts

Posted 08 March 2016 - 10:04 AM

thank you for your basics

#16 GiantNuker

  • Members
  • 3 posts

Posted 03 April 2016 - 06:49 PM

basicly linux shell :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users