Difference between revisions of "Creating a simple name reading program"
From ComputerCraft Wiki
(Corrected your mum) |
(Undo revision 4564 by 184.171.168.202 (talk) Dude, you're really messed up. AfterLifeLochie: Ban him?) |
||
Line 1: | Line 1: | ||
== The Code == | == The Code == | ||
This will be a tutorial on making a program that will read a name. | This will be a tutorial on making a program that will read a name. | ||
− | This is | + | This is the code: |
+ | <pre> | ||
+ | print("Enter Your Name: ") | ||
+ | local name = read() | ||
+ | print("Hello "..name..", that's a cool name.") | ||
</pre> | </pre> | ||
The print is pretty obvious, it puts the text on the screen and makes a new line. | The print is pretty obvious, it puts the text on the screen and makes a new line. | ||
− | Now the 'local name = | + | Now the 'local name = read()' sets 'name' as a variable which contains a string (piece of text) which the user typed, in this case it's his/her name. |
+ | And the last line will print some text, and the '"..name.."' concatenates (merges) the text before it with the text that the variable 'name' contains. | ||
+ | |||
+ | This is another version for my door: | ||
<pre> | <pre> | ||
textutils.slowPrint("Enter Your Name: ") | textutils.slowPrint("Enter Your Name: ") | ||
local name = read() | local name = read() | ||
print("Okay "..name..", door's open!") | print("Okay "..name..", door's open!") | ||
− | rs.setOutput("right",true) -- | + | rs.setOutput("right",true) -- this can be changed, "right" is the side of door / redstone |
+ | sleep(5) | ||
+ | os.shutdown() | ||
</pre> | </pre> | ||
[[Category:Programs]][[Category:Tutorials]] | [[Category:Programs]][[Category:Tutorials]] |
Revision as of 10:41, 4 December 2012
The Code
This will be a tutorial on making a program that will read a name. This is the code:
print("Enter Your Name: ") local name = read() print("Hello "..name..", that's a cool name.")
The print is pretty obvious, it puts the text on the screen and makes a new line. Now the 'local name = read()' sets 'name' as a variable which contains a string (piece of text) which the user typed, in this case it's his/her name. And the last line will print some text, and the '"..name.."' concatenates (merges) the text before it with the text that the variable 'name' contains.
This is another version for my door:
textutils.slowPrint("Enter Your Name: ") local name = read() print("Okay "..name..", door's open!") rs.setOutput("right",true) -- this can be changed, "right" is the side of door / redstone sleep(5) os.shutdown()