Difference between revisions of "Hello World Tutorial"
(→Creating the Program) |
|||
Line 6: | Line 6: | ||
Creating a Hello World program is a simple task and does not require much knowledge in Lua or ComputerCraft. | Creating a Hello World program is a simple task and does not require much knowledge in Lua or ComputerCraft. | ||
The first step is to create the program so we can edit it. Access your computer and type: | The first step is to create the program so we can edit it. Access your computer and type: | ||
− | + | <pre> | |
+ | edit helloworld | ||
+ | </pre> | ||
You will now have a blank program that you can edit. | You will now have a blank program that you can edit. | ||
− | We can make the computer print "Hello World!" in | + | We can make the computer print "Hello World!" in three different ways. |
To print it letter by letter, type: | To print it letter by letter, type: | ||
− | + | <pre> | |
+ | textutils.slowPrint("Hello World!") | ||
+ | </pre> | ||
+ | Note that this can be annoying for the user. | ||
To just print it, type: | To just print it, type: | ||
− | + | <pre> | |
+ | write("Hello World!\n") | ||
+ | </pre> | ||
+ | The \n at the end of the line makes the terminal go to the next line. | ||
+ | |||
+ | os.print does that automatically: | ||
+ | <pre> | ||
+ | print("Hello World!") | ||
+ | </pre> | ||
Now, press '''CTRL''' and make sure Save is selected, then press '''ENTER''' or '''RETURN'''. | Now, press '''CTRL''' and make sure Save is selected, then press '''ENTER''' or '''RETURN'''. | ||
Line 23: | Line 36: | ||
To test it, type: | To test it, type: | ||
− | + | <pre> | |
− | + | helloworld | |
− | + | </pre> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | Simple, isn't it? | |
− | + | ||
− | + |
Revision as of 20:37, 15 March 2012
This tutorial is for those who are just getting started with ComputerCraft.
Creating the Program
Creating a Hello World program is a simple task and does not require much knowledge in Lua or ComputerCraft. The first step is to create the program so we can edit it. Access your computer and type:
edit helloworld
You will now have a blank program that you can edit.
We can make the computer print "Hello World!" in three different ways.
To print it letter by letter, type:
textutils.slowPrint("Hello World!")
Note that this can be annoying for the user.
To just print it, type:
write("Hello World!\n")
The \n at the end of the line makes the terminal go to the next line.
os.print does that automatically:
print("Hello World!")
Now, press CTRL and make sure Save is selected, then press ENTER or RETURN. The program is now completed and saved, so let's exit edit mode. Press CTRL and select Exit by using the arrow keys. Once selected press ENTER or RETURN.
To test it, type:
helloworld
Simple, isn't it?