http://www.computercraft.info/wiki/api.php?action=feedcontributions&user=Pinkishu&feedformat=atomComputerCraft Wiki - User contributions [en]2024-03-28T22:56:13ZUser contributionsMediaWiki 1.24.1http://www.computercraft.info/wiki/index.php?title=Tostring&diff=4170Tostring2012-11-30T10:06:49Z<p>Pinkishu: removing API link</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=tostring<br />
|args=Object o<br />
|returns=[[string (type)|string]] representation of the Object <var>o</var><br />
|api=<br />
|addon=Lua<br />
|desc=Converts any passed object to it's string-representation.<br />
|examples=<br />
{{Example<br />
|desc=Convert an [[int (type)|integer]] to a [[string (type)|string]]<br />
|code=local a = tostring(1)<br />
|output= a = "1" ([[string (type)|string]])<br />
}}<br />
{{Example<br />
|desc=Convert a [[float (type)|float]] to a [[string (type)|string]]<br />
|code=local b = tostring(3.1415)<br />
|output= b = "3.1415" ([[string (type)|string]])<br />
}}<br />
}}<br />
<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.setPageTitle&diff=4168Printer.setPageTitle2012-11-30T10:05:31Z<p>Pinkishu: Category -> API Functions</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.setPageTitle<br />
|args=[[string (type)|string]] title<br />
|returns=none<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Sets the title of the page being printed<br />
|examples=<br />
{{Example<br />
|desc=Set the title of a page to be printed.<br />
|code=Printer.setPageTitle("Test page")<br />
|output=When the page is hovered-on in the inventory, the tooltip reads "Printed Page; Test page"<br />
}}<br />
}}<br />
<br />
[[Category:API_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.write&diff=4167Printer.write2012-11-30T10:05:21Z<p>Pinkishu: Category -> API Functions</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.write<br />
|args=[[string (type)|string]] text<br />
|returns=empty [[string (type)|string]] (bug?)<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Writes onto the paper<br />
|examples=<br />
{{Example<br />
|desc=Writes text onto the loaded paper, at the cursor's current position.<br />
This does not produce a new line, and anything else printed or written after this will be on the same line.<br />
|code=printer.write("Hello, World!")<br />
|output=Prints "Hello, World!" onto the loaded paper.<br />
}}<br />
}}<br />
<br />
[[Category:API_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.endPage&diff=4166Printer.endPage2012-11-30T10:04:56Z<p>Pinkishu: Category -> API Functions</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.endPage<br />
|args=none<br />
|returns=[[boolean|(boolean)]] If the page termination was successful.<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Terminates and prints the page loaded.<br />
|examples=<br />
{{Example<br />
|desc= Prints out the current page.<br />
|code=print(printer.endPage())<br />
|output=true if the page printed successfully, otherwise false<br />
}}<br />
}}<br />
<br />
[[Category:API_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.getPaperLevel&diff=4165Printer.getPaperLevel2012-11-30T10:03:55Z<p>Pinkishu: -> printer api</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.getPaperLevel<br />
|args=none<br />
|returns=Int_(type)<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Returns the total amount of paper in the printer.<br />
|examples=<br />
{{Example<br />
|desc=Prints paper level<br />
|code=print(printer.getPaperLevel())<br />
}}<br />
}}<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.newPage&diff=4164Printer.newPage2012-11-30T10:03:39Z<p>Pinkishu: -> printer api</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.newPage<br />
|args=none<br />
|returns=[[boolean|(boolean)]] If the page creation was successful.<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Creates a new page to be printed.<br />
|examples=<br />
{{Example<br />
|desc= Creates a new page.<br />
|code=print(printer.newPage())<br />
|output=true if the page creation was successful, otherwise false<br />
}}<br />
}}<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.endPage&diff=4163Printer.endPage2012-11-30T10:03:28Z<p>Pinkishu: -> printer api</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.endPage<br />
|args=none<br />
|returns=[[boolean|(boolean)]] If the page termination was successful.<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Terminates and prints the page loaded.<br />
|examples=<br />
{{Example<br />
|desc= Prints out the current page.<br />
|code=print(printer.endPage())<br />
|output=true if the page printed successfully, otherwise false<br />
}}<br />
}}<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.write&diff=4162Printer.write2012-11-30T10:03:19Z<p>Pinkishu: -> printer api</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.write<br />
|args=[[string (type)|string]] text<br />
|returns=empty [[string (type)|string]] (bug?)<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Writes onto the paper<br />
|examples=<br />
{{Example<br />
|desc=Writes text onto the loaded paper, at the cursor's current position.<br />
This does not produce a new line, and anything else printed or written after this will be on the same line.<br />
|code=printer.write("Hello, World!")<br />
|output=Prints "Hello, World!" onto the loaded paper.<br />
}}<br />
}}<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer.setPageTitle&diff=4161Printer.setPageTitle2012-11-30T10:03:07Z<p>Pinkishu: -> printer api</p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=printer.setPageTitle<br />
|args=[[string (type)|string]] title<br />
|returns=none<br />
|api=printer<br />
|addon=ComputerCraft<br />
|desc=Sets the title of the page being printed<br />
|examples=<br />
{{Example<br />
|desc=Set the title of a page to be printed.<br />
|code=Printer.setPageTitle("Test page")<br />
|output=When the page is hovered-on in the inventory, the tooltip reads "Printed Page; Test page"<br />
}}<br />
}}<br />
<br />
[[Category:Lua_Core_Functions]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Printer_(API)&diff=4160Printer (API)2012-11-30T10:02:14Z<p>Pinkishu: Remaking this page?</p>
<hr />
<div>The Printer API allows you to interact with printers.<br />
<br />
==Methods==<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
| [[printer.getPaperLevel]]()<br />
| <br />
|-<br />
| [[printer.newPage]]()<br />
|<br />
|-<br />
| [[printer.endPage]]()<br />
|<br />
|-<br />
| [[printer.write]]([[string]] text)<br />
|<br />
|-<br />
| [[printer.setPageTitle]]([[string]] title)<br />
|<br />
|}</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Talk:Gps_(program)&diff=2653Talk:Gps (program)2012-08-16T21:46:48Z<p>Pinkishu: </p>
<hr />
<div>==Spoiler tag?==<br />
Is there a wa to hide all that code until/unless the user clicks a button? That's a pretty big block of code :/<br />
[[User:Luingar|Luingar]] 22:59, 8 August 2012 (UTC)<br />
:It's at the end of the page anyway, so I don't see how it matters? [[User:Pinkishu|Pinkishu]] 23:46, 16 August 2012 (CEST)</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Talk:Gps_(program)&diff=2652Talk:Gps (program)2012-08-16T21:46:35Z<p>Pinkishu: </p>
<hr />
<div>==Spoiler tag?==<br />
Is there a wa to hide all that code until/unless the user clicks a button? That's a pretty big block of code :/<br />
[[User:Luingar|Luingar]] 22:59, 8 August 2012 (UTC)<br />
:It's at the end of the page anyway, so I don't see how it matters? [[User:Pinkishu|Pinkishu]] 24:46, 16 August 2012 (CEST)</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle_(API)&diff=2649Turtle (API)2012-08-16T16:55:22Z<p>Pinkishu: </p>
<hr />
<div>The Turtle API is used to work with your Turtles.<br />
{| border="1" cellpadding="2" cellspacing="0|"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
!style="background:#EEE" width="*"|Min version<br />
|-<br />
|[[turtle.craft]]()<br />
|Craft items using ingredients in the nine upper left slots<br />
|<br />
|-<br />
|[[turtle.forward]]()<br />
|Let the Turtle move forward<br />
|<br />
|-<br />
|[[turtle.back]]()<br />
|Let the Turtle move back<br />
|<br />
|-<br />
|[[turtle.up]]()<br />
|Let the Turtle move up<br />
|<br />
|-<br />
|[[turtle.down]]()<br />
|Let the Turtle move down <br />
|<br />
|-<br />
|[[turtle.turnLeft]]()<br />
|The Turtle turns left<br />
|<br />
|-<br />
|[[turtle.turnRight]]()<br />
|The Turtle turns right<br />
|<br />
|-<br />
|[[turtle.select]]( slotNum )<br />
|The Turtle selects the given Slot (1 is top left, 16 (9 in 1.33 and earlier) is bottom right)<br />
|<br />
|-<br />
|[[turtle.getItemCount]]( slotNum )<br />
|Counts how many items are in the given Slot<br />
|<br />
|-<br />
|[[turtle.getItemSpace]]( slotNum )<br />
|Counts how many items you need to fill the stack in the given Slot<br />
|<br />
|-<br />
|[[turtle.dig]]()<br />
|Breaks the Block in front<br />
|<br />
|-<br />
|[[turtle.attack]]()<br />
|Attacks in front of the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.attackDown]]()<br />
|Attacks under the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.attackUp]]()<br />
|Attacks over the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.digUp]]()<br />
|Breaks the Block above<br />
|<br />
|-<br />
|[[turtle.digDown]]()<br />
|Breaks the Block below<br />
|<br />
|-<br />
|[[turtle.place]]( [signText] )<br />
|Places a Block of the first available slot in front. Engrave [signText] on signs if provided.<br />
| 1.4<br />
|-<br />
|[[turtle.placeUp]]()<br />
|Places a Block of the first available slot above<br />
|<br />
|-<br />
|[[turtle.placeDown]]()<br />
|Places a Block of the first available slot below<br />
|<br />
|-<br />
|[[turtle.detect]]()<br />
|Detects if there is a Block in front<br />
|<br />
|-<br />
|[[turtle.detectUp]]()<br />
|Detects if there is a Block above<br />
|<br />
|-<br />
|[[turtle.detectDown]]()<br />
|Detects if there is a Block below<br />
|<br />
|-<br />
|[[turtle.compare]]()<br />
|Detects if the block in front is the same as the one in the currently selected slot<br />
|<br />
|-<br />
|[[turtle.compareUp]]()<br />
|Detects if the block above is the same as the one in the currently selected slot<br />
|<br />
|-<br />
|[[turtle.compareDown]]()<br />
|Detects if the block below is the same as the one in the currently selected slot<br />
|<br />
|-<br />
|[[turtle.compareTo]]( [slot] )<br />
|Compare the current selected slot and the given slot to see if the items are the same, yields true if they are the same, and false if not.<br />
| 1.4<br />
|-<br />
|[[turtle.drop]]( [count] )<br />
|Drops all items in the selected slot, or if [count] is specified, drops that many items.<br />If there is a inventory on the side it will try to place into the inventory, returning false if the inventory is full.<br />
|<br />
|-<br />
|[[turtle.suck]]()<br />
|Picks up an item from the ground or an inventory in front of the turtle. If the turtle can't pick up the item, the function yields false.<br />
| 1.4<br />
|-<br />
|[[turtle.refuel]]()<br />
|If the current selected slot contains a fuel item, it will consume it to give the turtle the ability to move.<br />Added in 1.4 and is only needed in hardcore turtle mode. If the current slot doesn't contain a fuel item, it yields false.<br />
| 1.4<br />
|-<br />
|[[turtle.getFuelLevel]]()<br />
|Returns the current fuel level of the turtle, this is the number of blocks the turtle can move.<br />In softcore turtle mode it yields "unlimited".<br />
| 1.4<br />
|}<br />
<br />
Trivia:<br />
During the 1.4 beta, turtle.getFuelLevel() in softcore(that is now turtleneedsfuel = 0) returned 9000.<br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Login_with_Roaming_Profiles&diff=2646Login with Roaming Profiles2012-08-16T14:28:50Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers how to make a password server and a password client. The server will host a Lua table of usernames and passwords and the client will remotely connect each start up, ask the user for their username and password and compare it to that on the password server.<br />
<br />
__TOC__<br />
<br />
== Setting Up ==<br />
As I'm sure you're aware, writing code directly into the computer terminal can be difficult, slow, and therefore annoying. I highly recommend writing/copying the following code into a Lua editor and then using FTP to transfer the documents across to the computer or disk. Please ensure you do not add the .lua extension.<br />
<br />
First craft two or more computers. One will act as your password server, any others will be connecting to that computer. Find the computer ID of your password server. This is important as we don't want to broadcast password requests and replies. In the following code I have also locked the requests to certain computers to ensure security but it is not a needed component of the code. If you decide to take the security as well, make a note of all of the ID's of the client computers. I found it useful to give each computer a label and then search for labels.txt on the server to map it out easily.<br />
<br />
Each computer you craft needs a [[modem|rednet modem]].<br />
<br />
== The Code ==<br />
<br />
=== Server Code ===<br />
<br />
os.pullEvent = os.pullEventRaw<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("This is a password server. There is no user interaction here.")<br />
print("Please find a computer and login there.") <br />
local firstCycle = true<br />
local validSender = false<br />
local modemSide = "left" -- change to the side of the computer your modem is on<br />
local valid = false<br />
users = { username1, username2 } --make sure users and passwords line up<br />
passwords = { password1, password2 }<br />
senders = { 13, 14, 15, 17 } -- computer ID's of the computers you want to accept requests from<br />
function bootUp()<br />
rednet.open(modemSide)<br />
end <br />
while true do <br />
validSender = false<br />
if firstCycle then<br />
bootUp()<br />
firstCycle = true<br />
end<br />
senderId, message, distance = rednet.receive()<br />
for i,v in ipairs(senders) do<br />
if v == senderId then<br />
validSender = true<br />
break<br />
end<br />
end<br />
if validSender then<br />
for i,v in ipairs(users) do<br />
if message == v then<br />
valid = true<br />
password = passwords[i]<br />
else<br />
valid = false<br />
end<br />
end<br />
if valid then<br />
rednet.send(senderId, password)<br />
else<br />
rednet.send(senderId, "Not Valid")<br />
end<br />
end<br />
end<br />
<br />
=== Client Code ===<br />
<br />
os.pullEvent = os.pullEventRaw<br />
local locker = true<br />
local failed = true<br />
local attempted_login = true<br />
local password_server = 17 -- change to the ID of your password server computer<br />
rednet.open("left") -- change to the side your rednet modem is on<br />
while locker do<br />
attempted_login = false<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("Welcome to a USERS PC : Roaming Profile Enabled")<br />
print("What would you like to do?")<br />
print("[1] Login (*)")<br />
print("[2] Shutdown")<br />
write("> ")<br />
local input = read()<br />
if input == "2" then<br />
os.shutdown()<br />
elseif input == "1" then<br />
attempted_login = true<br />
print("Please login...")<br />
write("Username: ")<br />
local username = read()<br />
write("Password: ")<br />
local password = read("*")<br />
rednet.send(password_server, username)<br />
senderId, message, distance = rednet.receive(5)<br />
if password == message then<br />
failed = false<br />
locker = false<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("Welcome ", username)<br />
else<br />
print("Not authorised.")<br />
sleep(1)<br />
end<br />
else<br />
print("Command not recognised...")<br />
sleep(2)<br />
end<br />
end<br />
<br />
== Thoughts and Notes ==<br />
If you change the client code, to "startup" and put it in the root directory, it works very well as a login system.<br />
You may also want to not put in the line <br />
os.pullEvent = os.pullEventRaw -- disables Ctrl+T<br />
as if it doesn't work first time it can be difficult to get out of the program.<br />
<br />
If you run Tekkit, find the 'World Anchor' block. If your server can afford the resources, place the block within a 3x3 grid of your password server. It will ensure that even if you leave the chunk, the password server still is operational. Otherwise you may find that you cannot login because you've left the chunk and the password server is no longer dealing with requests.<br />
<br />
<br />
[[Category:User Management]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Login_with_Roaming_Profiles&diff=2645Login with Roaming Profiles2012-08-16T14:27:38Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers how to make a password server and a password client. The server will host a Lua table of usernames and passwords and the client will remotely connect each start up, ask the user for their username and password and compare it to that on the password server.<br />
<br />
__TOC__<br />
<br />
== Setting Up ==<br />
As I'm sure you're aware, writing code directly into the computer terminal can be difficult, slow, and therefore annoying. I highly recommend writing/copying the following code into a Lua editor and then using FTP to transfer the documents across to the computer or disk. Please ensure you do not add the .lua extension.<br />
<br />
First craft two or more computers. One will act as your password server, any others will be connecting to that computer. Find the computer ID of your password server. This is important as we don't want to broadcast password requests and replies. In the following code I have also locked the requests to certain computers to ensure security but it is not a needed component of the code. If you decide to take the security as well, make a note of all of the ID's of the client computers. I found it useful to give each computer a label and then search for labels.txt on the server to map it out easily.<br />
<br />
Each computer you craft needs a [[modem|rednet modem]].<br />
<br />
== The Code ==<br />
<br />
=== Server Code ===<br />
<br />
os.pullEvent = os.pullEventRaw<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("This is a password server. There is no user interaction here.")<br />
print("Please find a computer and login there.") <br />
local firstCycle = true<br />
local validSender = false<br />
local modemSide = "left" -- change to the side of the computer your modem is on<br />
local valid = false<br />
users = { username1, username2 } //make sure users and passwords line up<br />
passwords = { password1, password2 }<br />
senders = { 13, 14, 15, 17 } -- computer ID's of the computers you want to accept requests from<br />
function bootUp()<br />
rednet.open(modemSide)<br />
end <br />
while true do <br />
validSender = false<br />
if firstCycle then<br />
bootUp()<br />
firstCycle = true<br />
end<br />
senderId, message, distance = rednet.receive()<br />
for i,v in ipairs(senders) do<br />
if v == senderId then<br />
validSender = true<br />
break<br />
end<br />
end<br />
if validSender then<br />
for i,v in ipairs(users) do<br />
if message == v then<br />
valid = true<br />
password = passwords[i]<br />
else<br />
valid = false<br />
end<br />
end<br />
if valid then<br />
rednet.send(senderId, password)<br />
else<br />
rednet.send(senderId, "Not Valid")<br />
end<br />
end<br />
end<br />
<br />
=== Client Code ===<br />
<br />
os.pullEvent = os.pullEventRaw<br />
local locker = true<br />
local failed = true<br />
local attempted_login = true<br />
local password_server = 17 -- change to the ID of your password server computer<br />
rednet.open("left") -- change to the side your rednet modem is on<br />
while locker do<br />
attempted_login = false<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("Welcome to a USERS PC : Roaming Profile Enabled")<br />
print("What would you like to do?")<br />
print("[1] Login (*)")<br />
print("[2] Shutdown")<br />
write("> ")<br />
local input = read()<br />
if input == "2" then<br />
os.shutdown()<br />
elseif input == "1" then<br />
attempted_login = true<br />
print("Please login...")<br />
write("Username: ")<br />
local username = read()<br />
write("Password: ")<br />
local password = read("*")<br />
rednet.send(password_server, username)<br />
senderId, message, distance = rednet.receive(5)<br />
if password == message then<br />
failed = false<br />
locker = false<br />
term.clear()<br />
term.setCursorPos(1,1)<br />
print("Welcome ", username)<br />
else<br />
print("Not authorised.")<br />
sleep(1)<br />
end<br />
else<br />
print("Command not recognised...")<br />
sleep(2)<br />
end<br />
end<br />
<br />
== Thoughts and Notes ==<br />
If you change the client code, to "startup" and put it in the root directory, it works very well as a login system.<br />
You may also want to not put in the line <br />
os.pullEvent = os.pullEventRaw -- disables Ctrl+T<br />
as if it doesn't work first time it can be difficult to get out of the program.<br />
<br />
If you run Tekkit, find the 'World Anchor' block. If your server can afford the resources, place the block within a 3x3 grid of your password server. It will ensure that even if you leave the chunk, the password server still is operational. Otherwise you may find that you cannot login because you've left the chunk and the password server is no longer dealing with requests.<br />
<br />
<br />
[[Category:User Management]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Talk:Turtle_(API)&diff=2642Talk:Turtle (API)2012-08-16T11:12:45Z<p>Pinkishu: </p>
<hr />
<div>Is there a way to detect a block's type? Preferably without picking it up; it would be nice to be able to write a function to check the block about to be broken against a list of "Do not break" blocks, such as Industrial craft's MFSU, which loses all held power when picked up. <br />
<br />
Also I request a way to set server-wide list of blocks immune to the turtle.dig() functions, such as say personal safes (Industrial Craft again).<small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:50.131.199.48|50.131.199.48]] ([[User talk:50.131.199.48|talk]] • [[Special:Contributions/50.131.199.48|contribs]]) </span></small><!-- Template:Unsigned --><br />
:As far as I know, there's no way to check the block type with the current API. Could be a feature in the future though, never know. {{User:Scarfacial/Signature|22:17 - 8 March 2012}}<br />
::Would be interesting to see if one could write a function for that. {{User:Banane9/Signature|22:43 - 9 March 2012}}<br />
:::i would see it too please. But i dont think that you can make that in a function<br />
:::[[User:Dude|Dude]] 22:13, 9 March 2012 (UTC)<br />
::::You can determine if the block matches the one in its inventory using turtle.select(slot) and then turtle.compare() or turtle.compareUp() or turtle.compareDown()<br />
<br />
== turtle collect ? ==<br />
<br />
i understand that the turtle can drop items from its inventory with turtle.drop( [amount] )<br />
but is there a way to make the turtle collect items (like a player would do) around and store it in inventory ?<br />
(from what i understand right now the turtle collects items taken from a digged block ?<br />
thanks<br />
:Nope they don't collect items that are already dropped --[[User:Banane9|Banane9]] 12:22, 11 July 2012 (UTC)<br />
<br />
== treefarm ==<br />
<br />
i have write a big programm (120 lines) that destory the tree full (with the leaves) when the tree is grown. so the turtle can plant an new tree an beginn at the start. My problem: the programm dont work and i cant find the faults... <small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Dude|Dude]] ([[User talk:Dude|talk]] • [[Special:Contributions/Dude|contribs]]) </span></small><!-- Template:Unsigned --><br />
:Maybe because the leaves of the tree decay and that f*cks up the code? We cant help you without seeing your code ;) --[[User:Banane9|Banane9]] 12:22, 11 July 2012 (UTC)<br />
::On a similar note, I have written a disassembler script which (mostly) disassembles arbitrary things from the top down, but it really gets messed up by doors and other turtles and pistons, it is basically because interacting with blocks only works well if the blocks don't change while you are trying to deal with them/use them for navigating.<br />
<br />
== Turtle API to detect block/item ID? ==<br />
<br />
I have a suggestion, what if you have a function like: turtle.getBlockID() which would return ID, damage value, or simmilar<br />
:Dan doesn't want Block IDs as they'd break the 4th wall. --[[User:Pinkishu|Pinkishu]] 13:12, 16 August 2012 (CEST)</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Monitor&diff=2585Monitor2012-08-11T22:20:18Z<p>Pinkishu: </p>
<hr />
<div>The '''Monitor''' is a block that can display text on its front side. When several screen blocks are placed on the same plane, it will form a single monitor. It is useful for displaying information at a server spawn, showing a program on the monitor, and even showing the status of a IC2 reactor! (provided you have [[CcSensors]] installed)<br />
<br />
===Recipe===<br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=glass_pane |C2=stone<br />
|A3=stone |B3=stone |C3=stone<br />
|Output=screen<br />
}}<br />
[[Category:Blocks]]<br />
<br />
===Using the Monitor===<br />
The command used to control a monitor: monitor [top, bottom, left, right, front or back] [the name of the command to display]<br />
<br />
So, in this case, if you typed "hello" in the name of the program part, the monitor would display "Hello World!".<br />
<br />
===Using the Monitor within the Lua interface===<br />
The monitor can be summoned through a command or through coding with the Lua command.<br />
<br />
The command used to control a monitor within the Lua interface: shell.run("monitor" "[top, bottom, left, right, front or back]" "[the name of the command to display]")<br />
<br />
For example, here is a way of summoning the monitor through a command:<br />
<br />
<tt>[[print]]("Hello Monitor!")<br />
<br />
[[Shell (API)|shell]].[[Shell.run|run]]("monitor", "right", "hello")</tt></div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2584Making a Password Protected Door2012-08-11T22:18:58Z<p>Pinkishu: no point in turning off the pc</p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Alternatively, you can put the computer adjacent to the iron door without using redstone.Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
<br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
if input == "password" then<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", true)<br />
[[sleep]](2)<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", false)<br />
end<br />
end<br />
<br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
[[Loops#The_While_loop|while]] true do <br />
[[term_(API)|term]].[[term.clear|clear]]() -- Clears the screen<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1) -- Fixes the cursor position<br />
[[write]]("Password: ") -- Prints 'Password: ' to the screen<br />
local input = [[read]]("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
if input == password then -- Checks if the user inputted the correct password<br />
[[term_(API)|term]].[[term.clear|clear]]() -- Already explained up top<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1)<br />
[[print]]("Password correct!") -- Prints 'Password correct!' to the screen<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,true) -- Output a redstone current to the side you specified<br />
[[sleep]](opentime) -- Wait the amount of seconds you specifed, then..<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
[[print]]("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
[[sleep]](2) -- Waits 2 seconds<br />
end<br />
end<br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
If you don't add this code to the top of your program, someone could terminate the lock and enter in a command and they can unlock your door without knowing the password. Adding the code is useful in Multiplayer.<br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle&diff=2583Turtle2012-08-11T22:18:00Z<p>Pinkishu: /* Recipes */</p>
<hr />
<div>'''Turtles''' are essentially robots, and were added in the 1.3 update. They run an OS (like the [[Console|consoles]]) named [[TurtleOS]]. They have the ability to place, break and detect blocks, move around and drop items in their inventory. The programs they run are stored on its internal memory or [[Floppy Disk|floppy disks]].<br />
<br />
The 1.4 update was focused on turtles and added new tools for them to use. Turtles can now in addition to pickaxes use: Hoes, crafting tables, axes, shovels and sword. The update also included a new fuel system for the turtles. Turtles also got a inventory upgrade from 9 slots to 16.<br />
<br />
Turtles are submersible and lavaproof. As such, they are extremely useful for mining near bedrock, where heavy lava flows can prevent access to diamonds and other rare finds.<br />
<br />
If you would like to know more about how to program them, have a look at the [[Turtle (API)|Turtle API]].<br />
<br />
==Floppy Disks==<br />
Turtles do not have a built-in floppy drive. As such they need a floppy drive placed beside them to access disks. However if the turtle is a Wireless turtle, the floppy drive and other peripherals must be placed on a side other than the side the wireless modem is on.<br />
<br />
==Power source==<br />
Turtles runs on fuel. Fuel is any item that works in a regular furnace, like coal and lava. The turtle gains 0.6 movement per half second the fuel would have burnt in a furnace.<br />
The turtle can move 1 block for each fuel count it got, for example, coal yields 96 block movements.<br />
<br />
=== Optional Non-fuel mode ===<br />
<br />
In this mode turtles use their internal redstone engine, they do not need to be re-charged, or any other form of external power.<br />
This is because redstone continuously emits low levels of energy, and the turtle's engine is very efficient.<br />
This mode can be turned on by editing the turtle config file (config/mod_CCTurtle.cfg) and setting turtleNeedsFuel to 0.<br />
<br />
==Farming==<br />
Turtles equipped with a hoe can till dirt.<br />
<br />
==Mining==<br />
Turtles crafted with a [[diamond pickaxe]], [[diamond axe]], or [[diamond shovel]], can break blocks, mine wood, and even break dirt and gravel, depending on the tool you used on it. The tools equipped on the turtle have no durability, and so can be used indefinitely without the need for any additional materials. When a turtle breaks the block it gets the item directly into its inventory. Different tools yields different drop, for example, an axe can break anything, but it won't get ores.<br />
<br />
==Crafting==<br />
Turtles equipped with a workbench can craft items. When crafting, the inventory must be clear of all items other than the ones needed for the recipe.<br />
<br />
==Melee==<br />
Turtles equipped with a sword can attack players and mobs. When a turtle kills a mob it will leave the experience orbs on the ground, but add the loot to it's inventory. Turtles can also attack with any tool, where axe is the second best after the sword.<br />
<br />
==Recipes==<br />
<br />
{|<br />
|+'''Crafting ingredients'''<br />
|-<br />
|Turtle<br />
|{{Crafting grid<br />
|A1=iron_ingot |B1=iron_ingot |C1=iron_ingot<br />
|A2=iron_ingot |B2=console |C2=iron_ingot<br />
|A3=iron_ingot |B3=chest |C3=iron_ingot<br />
|Output=turtle<br />
}}<br />
|-<br />
Turtles can be equipped with different peripherals and tools. A turtle can only have one tool and one peripheral.<br />
<br>The following tools can be equipped to a turtles: [[diamond pickaxe]], [[diamond axe]], [[diamond shovel]], [[diamond hoe]] and [[diamond sword]]<br />
<br>The following peripherals can be equipped to a turtles: [[modem|wireless modem]] and [[crafting table]].<br />
<br><br>'''Turtle recipe and examples for equipping a turtle with tools and peripherals.'''<br />
|Mining Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_pickaxe<br />
|Output=mining_turtle<br />
}}<br />
|-<br />
|Farming Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_hoe<br />
|Output=farming_turtle<br />
}}<br />
|-<br />
|Melee Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_sword<br />
|Output=melee_turtle<br />
}}<br />
|-<br />
|Felling Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_axe<br />
|Output=felling_turtle<br />
}}<br />
|-<br />
|Digging Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_shovel<br />
|Output=digging_turtle<br />
}}<br />
|-<br />
|Crafty Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=workbench<br />
|Output=Crafty_turtle<br />
}}<br />
|-<br />
|Wireless Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=modem<br />
|Output=wireless_turtle<br />
}}<br />
|-<br />
|Wireless Farming Turtle<br />
|{{Crafting grid<br />
|A2=modem |B2=turtle |C2=diamond_hoe<br />
|Output=wireless_farming_turtle<br />
}}<br />
|-<br />
|Wireless Felling Turtle<br />
|{{Crafting grid<br />
|A2=modem |B2=turtle |C2=diamond_axe<br />
|Output=wireless_felling_turtle<br />
}}<br />
|-<br />
|Wireless Digging Turtle<br />
|{{Crafting grid<br />
|A2=modem |B2=turtle |C2=diamond_shovel<br />
|Output=wireless_digging_turtle<br />
}}<br />
|-<br />
|Wireless Melee Turtle<br />
|{{Crafting grid<br />
|A2=modem |B2=turtle |C2=diamond_sword<br />
|Output=wireless_melee_turtle<br />
}}<br />
|-<br />
|Wireless Mining Turtle<br />
|{{Crafting grid<br />
|A2=modem |B2=turtle |C2=diamond_pickaxe<br />
|Output=wireless_mining_turtle<br />
}}<br />
|}<br />
<br />
<br />
[[Category:Blocks]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Peripheral_(API)&diff=2520Peripheral (API)2012-08-08T03:48:57Z<p>Pinkishu: Undo revision 2519 by 82.18.32.77 (talk)</p>
<hr />
<div>The peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the disk drive and monitor.<br /><br />
[[Console|Consoles]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''.<br />
<br />
==Methods==<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="210px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[peripheral.isPresent]]( side )<br />
|Returns '''true''' if a peripheral is present on ''side''.<br />
|-<br />
|[[peripheral.getType]]( side )<br />
|Returns the type or peripheral present on ''side'', nothing returned if ''side'' is empty.<br />
|-<br />
|[[peripheral.getMethods]]( side )<br />
|Returns a table containing all methods for peripheral on ''side''.<br />
|-<br />
|[[peripheral.call]]( side, methodName, param1, param2, ... )<br />
|Sends a function call to peripheral located on ''side''. Return values match those of called method.<br /><br />
'''Note:''' ''methodName'' is a string.<br />
|-<br />
|[[peripheral.wrap]]( side )<br />
|Returns a handle to the peripheral located on ''side''. If assigned to a variable, it can be used to call all methods available from that peripheral, as if calling '''peripheral.call()''', e.g.:<br /><br />
fdd = peripheral.wrap("left")<br /><br />
fdd.someMethod()<br /><br />
''- is the same as -''<br /><br />
peripheral.call("left","someMethod")<br />
|}<br />
<br />
==Events==<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="210px"|Event name<br />
!style="background:#EEE" width="*"|Description<br />
!style="background:#EEE" width="*"|Parameters<br />
|-<br />
|peripheral<br />
|Fired when peripheral is attached<br />
|side<br />
|-<br />
|peripheral_detach<br />
|Fired when peripheral is removed<br />
|side<br />
|}<br />
==Monitor==<br />
List of methods:<br />
<br />
'''''mon'' stands for the variable you wrapped the monitor to.'''<br />
''Example:'' mon = peripheral.wrap( "top" )<br />
<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="210px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[mon.write|''mon''.write]]()<br />
|Write to the Monitor's screen.<br />
|-<br />
|[[mon.scroll|''mon''.scroll]]( n )<br />
|Scrolls the monitor screen.<br />
|-<br />
|[[mon.setCursorPos|''mon''.setCursorPos]]( x, y )<br />
|Sets the cursor position on the Monitor.<br />
|-<br />
|[[mon.setCursorBlink|''mon''.setCursorBlink]]( b )<br />
|Enables or disables cursor blinking.<br />
|-<br />
|[[mon.getCursorPos|''mon''.getCursorPos]]()<br />
|Returns two arguments containing the x and the y position of the cursor on the Monitor.<br />
|-<br />
|[[mon.getSize|''mon''.getSize]]()<br />
|Returns two arguments containing the x and the y values stating the size of the Monitor. <br />
|-<br />
|[[mon.clear|''mon''.clear]]()<br />
|Clears the Monitor.<br />
|-<br />
|[[mon.clearLine|''mon''.clearLine]]( line )<br />
|Clears the line the cursor is on.<br />
|-<br />
|[[mon.setTextScale|''mon''.setTextScale]]( scale )<br />
|Sets the size of the text on the Monitor. Textscale can be between 0.5 and 5, with increments of 0.5.<br />
|}<br />
==Computers==<br />
List of methods:<br />
<br />
'''''computer'' stands for the variable you wrapped the computer to.'''<br />
''Example:'' computer = peripheral.wrap( "top" )<br />
<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="210px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[computer.turnOn|''computer''.turnOn]]()<br />
|Turns on the Computer or Turtle.<br />
|-<br />
|[[computer.shutdown|''computer''.shutdown]]()<br />
|Shuts off the Computer or Turtle.<br />
|-<br />
|[[computer.reboot|''computer''.reboot]]()<br />
|Reboots the Computer or Turtle.<br />
|-<br />
|[[computer.getID|''computer''.getID]]()<br />
|Gets the ID of the Computer or Turtle.<br />
|}<br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2490Making a Password Protected Door2012-08-06T11:09:14Z<p>Pinkishu: Undo revision 2488 by 88.159.195.123 (talk)</p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Alternatively, you can put the computer adjacent to the iron door without using redstone.Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
<br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
if input == "password" then<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", true)<br />
[[sleep]](2)<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", false)<br />
end<br />
end<br />
<br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
[[Loops#The_While_loop|while]] true do <br />
[[term_(API)|term]].[[term.clear|clear]]() -- Clears the screen<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1) -- Fixes the cursor position<br />
[[write]]("Password: ") -- Prints 'Password: ' to the screen<br />
local input = [[read]]("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
[[term_(API)|term]].[[term.clear|clear]]() -- Already explained up top<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1)<br />
if input == password then -- Checks if the user inputted the correct password<br />
[[print]]("Password correct!") -- Prints 'Password correct!' to the screen<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,true) -- Output a redstone current to the side you specified<br />
[[sleep]](opentime) -- Wait the amount of seconds you specifed, then..<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
[[print]]("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
[[sleep]](2) -- Waits 2 seconds<br />
end<br />
end<br />
<br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
If you don't add this code to the top of your program, someone could terminate the lock and enter in a command and they can unlock your door without knowing the password. Adding the code is useful in Multiplayer.<br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Wireless_Modem&diff=2479Wireless Modem2012-08-05T15:49:19Z<p>Pinkishu: </p>
<hr />
<div>== Description ==<br />
'''Modems''' are blocks which can be used to wirelessly transfer data between [[Console|consoles]] and [[Turtle|turtles]], using "rednet" commands.<br />
To place a modem on a side of your console, click on the console with the right mouse button while sneaking (with standard settings: holding the left shift button).<br />
<br />
It is also possible to turn the modem on and off by typing "rednet.open ( side )" to open and "rednet.close ( side )" to close.<br />
<br />
Modems can send messages to other modems located up to 64 meters away, or 16 meters during a thunderstorm.<br />
As of 1.4 Modem range is increased with higher altitudes. If there is no thunderstorm, the range will always be higher than 64, and at max altitude you would have a range of 384 meters.<br />
<br />
In 1.4 and 1.41 there is a miss calculation that causes the range to only be 381 meters at max altitude.<br />
<br />
== Recipe ==<br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=redstone_torch |C2=stone<br />
|A3=stone |B3=stone |C3=stone<br />
|Output=modem<br />
}}<br />
== Example ==<br />
* Place 2 consoles and add modems to them by clicking the right mouse button while sneaking.<br />
* Access them, and start Lua.<br />
* Once Lua has started, type "[[rednet_(API)|rednet]].[[rednet.open|open]] ("<relative location to modem, e.g. left, right>")" on both consoles.<br />
* Check if there exists a connection: a dim, red light should be found on the modem.<br />
* Type on one console "[[rednet_(API)|rednet]].[[rednet.receive|receive]] (60)". This will make the console freeze for 60 seconds, or until it has received a signal from the other console.<br />
* Now, type "[[rednet_(API)|rednet]].[[rednet.broadcast|broadcast]] ('<your message>')" on the other console. This should send your message to all consoles connected.<br />
* Opening the first console should show the message written on the second console.<br />
<br />
<br />
[[Rednet (API)|More help on Rednet]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle&diff=2449Turtle2012-08-02T11:32:25Z<p>Pinkishu: /* Power source */</p>
<hr />
<div>'''Turtles''' are essentially robots, and were added in the 1.3 update. They run an OS (like the [[Console|consoles]]) named [[TurtleOS]]. They have the ability to place, break and detect blocks, move around and drop items in their inventory. The programs they run are stored on it's internal memory or [[Floppy Disk|floppy disks]].<br />
<br />
The 1.4 update was focused on turtles and added new tools for them to use. Turtles can now in addition to pickaxes use: Hoes, crafting tables, axes, shovels and sword. The update also included a new fuel system for the turtles.<br />
<br />
Turtles are submersible and lavaproof. As such, they are extremely useful for mining near bedrock, where heavy lava flows can prevent access to diamonds and other rare finds.<br />
<br />
If you would like to know more about how to program them, have a look at the [[Turtle (API)|Turtle API]].<br />
<br />
==Floppy Disks==<br />
Turtles do not have a built-in floppy drive. As such they need a floppy drive placed beside them to access disks. However if the turtle is a Wireless turtle, the floppy drive and other peripherals must be placed on a side other than the side the wireless modem is on.<br />
<br />
==Power source==<br />
Turtles runs on fuel. Fuel is any item that works in a regular furnace, like coal and lava. The turtle gains 0.6 movement per half second the fuel would have burnt in a furnace.<br />
The turtle can move 1 block for each fuel count it got, for example, coal yields 96 block movements.<br />
<br />
=== '''Optional Non-fuel mode''' ===<br />
<br />
In this mode turtles use their internal redstone engine, they do not need to be re-charged, or any other form of external power.<br /><br />
This is because redstone continuously emits low levels of energy, and the turtle's engine is very efficient.<br /><br />
This mode can be turned on by editing the config file and setting turtleNeedsFuel to 0.<br />
<br />
==Farming==<br />
Turtles equipped with a hoe can till dirt.<br />
<br />
==Mining==<br />
Turtles crafted with a [[diamond pickaxe]], [[diamond axe]], [[diamond shovel]], can break blocks, mine wood, and even break dirt and gravel, depending on the tool you used on it. The tools equipped on the turtle have no durability, and so can be used indefinitely without the need for any additional materials. When a turtle breaks the block it gets the item directly into its inventory. Different tools yields different drop, for example, an axe can break anything, but it won't get ores.<br />
<br />
==Crafting==<br />
Turtles equipped with a workbench can craft items. When crafting the upper left 3x3 part of the turtles inventory can only contain the items needed for the recipe.<br />
<br />
==Melee==<br />
Turtles equipped with a sword can attack players and mobs. When a turtle kills a mob it will leave the experience orbs on the ground, but add the loot to it's inventory. Turtles can also attack with any tool, where axe is the second best after the sword.<br />
<br />
==Recipes==<br />
<br />
{|<br />
|+'''Crafting ingredients'''<br />
|-<br />
|Turtle<br />
|{{Crafting grid<br />
|A1=iron_ingot |B1=iron_ingot |C1=iron_ingot<br />
|A2=iron_ingot |B2=console |C2=iron_ingot<br />
|A3=iron_ingot |B3=chest |C3=iron_ingot<br />
|Output=turtle<br />
}}<br />
|-<br />
|Mining Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_pickaxe<br />
|Output=mining_turtle<br />
}}<br />
|-<br />
|Wireless Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=modem<br />
|Output=wireless_turtle<br />
}}<br />
|-<br />
|Wireless Mining Turtle<br />
|{{Crafting grid<br />
|A1=modem |B1=turtle |C1=diamond_pickaxe<br />
|Output=wireless_mining_turtle<br />
}}<br />
|}<br />
<br />
<br />
[[Category:Blocks]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle&diff=2448Turtle2012-08-02T11:32:02Z<p>Pinkishu: /* Power source */</p>
<hr />
<div>'''Turtles''' are essentially robots, and were added in the 1.3 update. They run an OS (like the [[Console|consoles]]) named [[TurtleOS]]. They have the ability to place, break and detect blocks, move around and drop items in their inventory. The programs they run are stored on it's internal memory or [[Floppy Disk|floppy disks]].<br />
<br />
The 1.4 update was focused on turtles and added new tools for them to use. Turtles can now in addition to pickaxes use: Hoes, crafting tables, axes, shovels and sword. The update also included a new fuel system for the turtles.<br />
<br />
Turtles are submersible and lavaproof. As such, they are extremely useful for mining near bedrock, where heavy lava flows can prevent access to diamonds and other rare finds.<br />
<br />
If you would like to know more about how to program them, have a look at the [[Turtle (API)|Turtle API]].<br />
<br />
==Floppy Disks==<br />
Turtles do not have a built-in floppy drive. As such they need a floppy drive placed beside them to access disks. However if the turtle is a Wireless turtle, the floppy drive and other peripherals must be placed on a side other than the side the wireless modem is on.<br />
<br />
==Power source==<br />
Turtles runs on fuel. Fuel is any item that works in a regular furnace, like coal and lava. The turtle gains 0.6 movement per half second the fuel would have burnt in a furnace.<br />
The turtle can move 1 block for each fuel count it got, for example, coal yields 96 block movements.<br />
<br />
=== '''Optional Non-fuel mode''' ===<br />
<br />
In this mode turtles use their internal redstone engine, they do not need to be re-charged, or any other form of external power.<br />
This is because redstone continuously emits low levels of energy, and the turtle's engine is very efficient.<br />
This mode can be turned on by editing the config file and setting turtleNeedsFuel to 0.<br />
<br />
==Farming==<br />
Turtles equipped with a hoe can till dirt.<br />
<br />
==Mining==<br />
Turtles crafted with a [[diamond pickaxe]], [[diamond axe]], [[diamond shovel]], can break blocks, mine wood, and even break dirt and gravel, depending on the tool you used on it. The tools equipped on the turtle have no durability, and so can be used indefinitely without the need for any additional materials. When a turtle breaks the block it gets the item directly into its inventory. Different tools yields different drop, for example, an axe can break anything, but it won't get ores.<br />
<br />
==Crafting==<br />
Turtles equipped with a workbench can craft items. When crafting the upper left 3x3 part of the turtles inventory can only contain the items needed for the recipe.<br />
<br />
==Melee==<br />
Turtles equipped with a sword can attack players and mobs. When a turtle kills a mob it will leave the experience orbs on the ground, but add the loot to it's inventory. Turtles can also attack with any tool, where axe is the second best after the sword.<br />
<br />
==Recipes==<br />
<br />
{|<br />
|+'''Crafting ingredients'''<br />
|-<br />
|Turtle<br />
|{{Crafting grid<br />
|A1=iron_ingot |B1=iron_ingot |C1=iron_ingot<br />
|A2=iron_ingot |B2=console |C2=iron_ingot<br />
|A3=iron_ingot |B3=chest |C3=iron_ingot<br />
|Output=turtle<br />
}}<br />
|-<br />
|Mining Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_pickaxe<br />
|Output=mining_turtle<br />
}}<br />
|-<br />
|Wireless Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=modem<br />
|Output=wireless_turtle<br />
}}<br />
|-<br />
|Wireless Mining Turtle<br />
|{{Crafting grid<br />
|A1=modem |B1=turtle |C1=diamond_pickaxe<br />
|Output=wireless_mining_turtle<br />
}}<br />
|}<br />
<br />
<br />
[[Category:Blocks]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Getting_Started&diff=2395Getting Started2012-07-28T18:02:50Z<p>Pinkishu: Undo revision 2394 by 96.18.243.78 (talk)</p>
<hr />
<div>== Prerequisite: Installing the mods ==<br />
'''It is very important to read everything carefully before asking questions.'''<br />
'''Also, the latest version this mod may not be compatible with the current Minecraft release.'''<br />
<br />
# Install [http://lexmanos.no-ip.org:8080/job/Forge/Recommended/ Minecraft Forge Recommended Build 1.2.5]<br />
# Download the latest version of [http://www.minecraftforum.net/topic/892282- ComputerCraft 1.4 (1.2.5)]<br />
# Extract the .zip file in *minecraft folder*\mods\. (Tip: If on Windows, on the main screen of Minecraft, go to 'Texture Packs' and click on 'Open texture pack folder'. Go up one folder, there's your Minecraft folder. If on Mac, open Finder, hit Command+Shift+G and type ~/Library/ then hit enter, open 'Application Support' then open 'minecraft')<br />
<br />
== Step 1: Crafting the console ==<br />
The recipe is simple:<br /><br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=redstone |C2=stone<br />
|A3=stone |B3=glass pane |C3=stone<br />
|Output=console<br />
}}<br />
<br /><br />
<br />
Right click on the console to use it.<br /><br />
These are important to remember:<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Shortcut<br />
!style="background:#EEE" width="*"|Usage<br />
|-<br />
|CTRL + T<br />
|Closes the current program.<br />
|-<br />
|CTRL + R<br />
|Reboots the console.<br />
|-<br />
|CTRL + S<br />
|Forcefully shuts down the computer.<br />
|}<br />
NOTE: You have to hold the keyboard shortcuts down for at least 1 second!<br /><br />
These are forced and will close the current program, even if it is still running.<br />
<br />
== Step 2: Wiring it all up ==<br />
The console accepts many forms of redstone. For simple structures, such as a password protected door, only a single line of redstone is needed.<br />
However, this mod can do much more. If you need to connect multiple wires to one side, you can just use RedPower's cables. Easy peasy.<br />
Or, you don't do anything in this part. The computer has some great games shipped with and it is even capable of loading web pages.<br />
<br />
== Step 3: Programming your system ==<br />
If you've programmed before this shouldn't be hard. It'll feel very comfortable.<br />
<br />
Type<br />
edit <filename><br />
in the terminal to open the included feature-rich <!-- Save and exit!!! --> text editor. To get the hang of Lua if you're new, use<br />
edit /rom/programs/hello<br />
to view the code of a simple program 'hello'.<br />
<br />
Navigating is easy.<br />
> ls<br />
rom<br />
> cd rom<br />
rom> ls<br />
apis help programs<br />
startup<br />
rom> cd programs<br />
rom/programs> cd /<br />
><br />
To say it in English: ls '''l'''i'''s'''ts the files and folders in a directory, while cd changes the '''c'''urrent '''d'''irectory. / is the root of the computer.<br />
Again, you don't have to program, but it's a big part of the mod. But you can still play those games.<br />
<br />
== Step 4: Test it ==<br />
Make sure that your program is bug-proof before using it as something important. A system controlling the state of an IndustrialCraft² Mark-III Nuclear Reactor to prevent it from overheating shouldn't crash every now and then with "Too long without yielding".<br />
<br />
== Step 5: Extend it ==<br />
Give back your part to the community. Help others on the forums or improve the wiki. Or, make your own OS or shell to run on the computers and share it with everybody. You can even create your own peripheral blocks using the API to create even a bigger system. A mainframe, for example.</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle_(API)&diff=2390Turtle (API)2012-07-28T14:29:16Z<p>Pinkishu: </p>
<hr />
<div>The Turtle API is used to work with your Turtles.<br />
{| border="1" cellpadding="2" cellspacing="0|"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
!style="background:#EEE" width="*"|Min version<br />
|-<br />
|[[turtle.forward]]()<br />
|Let the Turtle move forward<br />
|<br />
|-<br />
|[[turtle.back]]()<br />
|Let the Turtle move back<br />
|<br />
|-<br />
|[[turtle.up]]()<br />
|Let the Turtle move up<br />
|<br />
|-<br />
|[[turtle.down]]()<br />
|Let the Turtle move down <br />
|<br />
|-<br />
|[[turtle.turnLeft]]()<br />
|The Turtle turns left<br />
|<br />
|-<br />
|[[turtle.turnRight]]()<br />
|The Turtle turns right<br />
|<br />
|-<br />
|[[turtle.select]]( slotNum )<br />
|The Turtle selects the given Slot (1 is top left, 16 is bottom right)<br />
|<br />
|-<br />
|[[turtle.getItemCount]]( slotNum )<br />
|Counts how many items are in the given Slot<br />
|<br />
|-<br />
|[[turtle.getItemSpace]]( slotNum )<br />
|Counts how many items you need to fill the stack in the given Slot<br />
|<br />
|-<br />
|[[turtle.dig]]()<br />
|Breaks the Block in front<br />
|<br />
|-<br />
|[[turtle.attack]]()<br />
|Attacks in front of the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.attackDown]]()<br />
|Attacks under the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.attackUp]]()<br />
|Attacks over the turtle.<br />
| 1.4<br />
|-<br />
|[[turtle.digUp]]()<br />
|Breaks the Block above<br />
|<br />
|-<br />
|[[turtle.digDown]]()<br />
|Breaks the Block below<br />
|<br />
|-<br />
|[[turtle.place]]()<br />
|Places a Block of the first available slot in front<br />
|<br />
|-<br />
|[[turtle.placeUp]]()<br />
|Places a Block of the first available slot above<br />
|<br />
|-<br />
|[[turtle.placeDown]]()<br />
|Places a Block of the first available slot below<br />
|<br />
|-<br />
|[[turtle.detect]]()<br />
|Detects if there is a Block in front<br />
|<br />
|-<br />
|[[turtle.detectUp]]()<br />
|Detects if there is a Block above<br />
|<br />
|-<br />
|[[turtle.detectDown]]()<br />
|Detects if there is a Block below<br />
|<br />
|-<br />
|[[turtle.compare]]()<br />
|Detects if the block in front is the same as the one in the first available slot<br />
|<br />
|-<br />
|[[turtle.compareUp]]()<br />
|Detects if the block above is the same as the one in the first available slot<br />
|<br />
|-<br />
|[[turtle.compareDown]]()<br />
|Detects if the block below is the same as the one in the first available slot<br />
|<br />
|-<br />
|[[turtle.compareTo]]( [slot] )<br />
|Compare the current selected slot and the given slot to see if the items are the same, yields true if they are the same, and false if not.<br />
| 1.4<br />
|-<br />
|[[turtle.drop]]( [count] )<br />
|Drops all items in the selected slot, or if [count] is specified, drops that many items.<br />If there is a inventory on the side it will try to place into the inventory, returning false if the inventory is full.<br />
|<br />
|-<br />
|[[turtle.suck]]()<br />
|Picks up an item from the ground or an inventory at the side, if the turtle can't pickup the item the function yields false.<br />
| 1.4<br />
|-<br />
|[[turtle.refuel]]()<br />
|If the current selected slot contains a fuel item, it will consume it to give the turtle the ability to move.<br />Added in 1.4 and is only needed in hardcore turtle mode. If the current slot doesn't contain a fuel item, it yields false.<br />
| 1.4<br />
|-<br />
|[[turtle.getFuelLevel]]()<br />
|Returns the current fuel level of the turtle, this is the number of blocks the turtle can move.<br />In softcore turtle mode it yields "unlimited".<br />
| 1.4<br />
|}<br />
<br />
Trivia:<br />
During the 1.4 beta, turtle.getFuelLevel() in softcore returned 9000.<br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle.refuel&diff=2386Turtle.refuel2012-07-28T14:22:23Z<p>Pinkishu: </p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=turtle.refuel<br />
|args=<br />
|api=turtle<br />
|returns=[[boolean]] whether the item is a fuel.<br />
|addon=ComputerCraft<br />
|desc=Fills the turtle with fuel.<br />
|examples=<br />
{{Example<br />
|desc=Fills the turtle.withFuel<br />
|code=turtle.refuel()<br />
|output=true if the item is a fuel, false if not<br />
}}<br />
}}<br />
<br />
== Fuel Values ==<br />
Fuel values with IC2 items.<br />
<br />
{| class="wikitable sortable"<br />
! Item<br />
! Movement gained<br />
|-<br />
| Biofuel Can<br />
| 624<br />
|- <br />
| Scrap<br />
| 21<br />
|-<br />
| Wooden Tools<br />
| 12<br />
|-<br />
| Lava<br />
| 1200<br />
|-<br />
| Blaze Rod<br />
| 144<br />
|-<br />
| Wood Blocks<br />
| 18<br />
|-<br />
| Sticks<br />
| 6<br />
|- <br />
| Sugar Cane<br />
| 3<br />
|-<br />
| Coalfuel Can<br />
| 1824<br />
|-<br />
| Coal<br />
| 96<br />
|-<br />
| Mushroom<br />
| 18<br />
|}</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle.refuel&diff=2384Turtle.refuel2012-07-28T14:20:45Z<p>Pinkishu: </p>
<hr />
<div>{{lowercase}}<br />
{{Function<br />
|name=turtle.refuel<br />
|args=<br />
|api=turtle<br />
|returns=[[boolean]] whether the item is a fuel.<br />
|addon=ComputerCraft<br />
|desc=Fills the turtle with fuel.<br />
|examples=<br />
{{Example<br />
|desc=Fills the turtle.withFuel<br />
|code=[[print]](turtle.refuel())<br />
|output=true if the item is a fuel, false if not<br />
}}<br />
<br />
== Fuel Values ==<br />
Fuel values with IC2 items.<br />
<br />
{| class="wikitable sortable"<br />
! Item<br />
! Movement gained<br />
|-<br />
| Biofuel Can<br />
| 624<br />
|- <br />
| Scrap<br />
| 21<br />
|-<br />
| Wooden Tools<br />
| 12<br />
|-<br />
| Lava<br />
| 1200<br />
|-<br />
| Blaze Rod<br />
| 144<br />
|-<br />
| Wood Blocks<br />
| 18<br />
|-<br />
| Sticks<br />
| 6<br />
|- <br />
| Sugar Cane<br />
| 3<br />
|-<br />
| Coalfuel Can<br />
| 1824<br />
|-<br />
| Coal<br />
| 96<br />
|-<br />
| Mushroom<br />
| 18<br />
|}</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle_(API)&diff=2373Turtle (API)2012-07-28T10:28:55Z<p>Pinkishu: </p>
<hr />
<div>The Turtle API is used to work with your Turtles.<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[turtle.forward]]()<br />
|Let the Turtle move forward<br />
|-<br />
|[[turtle.back]]()<br />
|Let the Turtle move back<br />
|-<br />
|[[turtle.up]]()<br />
|Let the Turtle move up<br />
|-<br />
|[[turtle.down]]()<br />
|Let the Turtle move down <br />
|-<br />
|[[turtle.turnLeft]]()<br />
|The Turtle turns left<br />
|-<br />
|[[turtle.turnRight]]()<br />
|The Turtle turns right<br />
|-<br />
|[[turtle.select]]( slotNum )<br />
|The Turtle selects the given Slot (1 is top left, 16 is bottom right)<br />
|-<br />
|[[turtle.getItemCount]]( slotNum )<br />
|Counts how many items are in the given Slot<br />
|-<br />
|[[turtle.getItemSpace]]( slotNum )<br />
|Counts how many items you need to fill the stack in the given Slot<br />
|-<br />
|[[turtle.dig]]()<br />
|Breaks the Block in front<br />
|-<br />
|[[turtle.attack]]()<br />
|Attacks in front of the turtle.<br />
|-<br />
|[[turtle.attackDown]]()<br />
|Attacks under the turtle.<br />
|-<br />
|[[turtle.attackUp]]()<br />
|Attacks over the turtle.<br />
|-<br />
|[[turtle.digUp]]()<br />
|Breaks the Block above<br />
|-<br />
|[[turtle.digDown]]()<br />
|Breaks the Block below<br />
|-<br />
|[[turtle.place]]()<br />
|Places a Block of the first available slot in front<br />
|-<br />
|[[turtle.placeUp]]()<br />
|Places a Block of the first available slot above<br />
|-<br />
|[[turtle.placeDown]]()<br />
|Places a Block of the first available slot below<br />
|-<br />
|[[turtle.detect]]()<br />
|Detects if there is a Block in front<br />
|-<br />
|[[turtle.detectUp]]()<br />
|Detects if there is a Block above<br />
|-<br />
|[[turtle.detectDown]]()<br />
|Detects if there is a Block below<br />
|-<br />
|[[turtle.compare]]()<br />
|Detects if the block in front is the same as the one in the first available slot<br />
|-<br />
|[[turtle.compareUp]]()<br />
|Detects if the block above is the same as the one in the first available slot<br />
|-<br />
|[[turtle.compareDown]]()<br />
|Detects if the block below is the same as the one in the first available slot<br />
|-<br />
|[[turtle.compareTo]]( [slot] )<br />
|Compare the current selected slot and the given slot to see if the items are the same, yields true if they are the same, and false if not.<br />
|-<br />
|[[turtle.drop]]( [count] )<br />
|Drops all items in the selected slot, or if [count] is specified, drops that many items. If there is a inventory on the side it will try to place into the inventory, returning false if the inventory is full.<br />
|-<br />
|[[turtle.suck]]()<br />
|Picks up an item from the ground or an inventory at the side, if the turtle can't pickup the item the function yields false.<br />
|-<br />
|[[turtle.refuel]]()<br />
|If the current selected slot contains a fuel item, it will consume it to give the turtle the ability to move. Added in 1.4 and is only needed in hardcore turtle mode. If the current slot doesn't contain a fuel item, it yields false.<br />
|-<br />
|[[turtle.getFuelLevel]]()<br />
|Returns the current fuel level of the turtle, this is the number of blocks the turtle can move. In softcore turtle mode it yields "unlimited".<br />
|}<br />
<br />
Trivia:<br />
In 1.4 turtle.getFuelLevel() in softcore returned 9000 <br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle&diff=2365Turtle2012-07-27T22:48:10Z<p>Pinkishu: Merging edits</p>
<hr />
<div>'''Turtles''' are essentially robots, and were added in the 1.3 update. They run an OS (like the [[Console|consoles]]) named [[TurtleOS]]. They have the ability to place, break and detect blocks, move around and drop items in their inventory. The programs they run are stored on it's internal memory or [[Floppy Disk|floppy disks]].<br />
<br />
The 1.4 update was focused on turtles and added new tools for them to use. Turtles can now in addition to pickaxes use: Hoes, crafting tables, axes, shovels and sword. The updated also included a new fuel system for the turtles.<br />
<br />
Turtles are submersible and lavaproof. As such, they are extremely useful for mining near bedrock, where heavy lava flows can prevent access to diamonds and other rare finds.<br />
<br />
If you would like to know more about how to program them, have a look at the [[Turtle (API)|Turtle API]].<br />
<br />
==Floppy Disks==<br />
Turtles do not have a built-in floppy drive. As such they need a floppy drive placed beside them to access disks. However if the turtle is a Wireless turtle, the floppy drive and other peripherals must be placed on a side other than the side the wireless modem is on.<br />
<br />
==Power source==<br />
Hardcore(default and added in 1.4):<br />
Turtles runs on fuel. Fuel is any item that works in a regular furnace, like coal and lava. The turtle gains 0.6 movement per half second the fuel would have burnt in a furnace.<br />
The turtle can move 1 block for each fuel count it got, for example, coal yields 96 block movements.<br />
<br />
Non Hardcore:<br />
Turtles have been equipped with a redstone engine, they do not need to be re-charged, or any other form of external power.<br />
This is because redstone continuously emits low levels of energy, and the turtle's engine is very efficient.<br />
==Farming==<br />
Turtles equipped with a hoe can till dirt.<br />
<br />
==Mining==<br />
Turtles crafted with a [[diamond pickaxe]], [[diamond axe]], [[diamond shovel]], can break blocks, mine wood, and even break dirt and gravel, depending on the tool you used on it. The tools equipped on the turtle have no durability, and so can be used indefinitely without the need for any additional materials. When a turtle breaks the block it gets the item directly into its inventory. Different tools yields different drop, for example, an axe can break anything, but it won't get ores.<br />
<br />
==Crafting==<br />
Turtles equipped with a workbench can craft items. When crafting the upper left 3x3 part of the turtles inventory can only contain the items needed for the recipe.<br />
<br />
==Melee==<br />
Turtles equipped with a sword can attack players and mobs. When a turtle kills a mob it will leave the experience orbs on the ground, but add the loot to it's inventory. Turtles can also attack with any tool, where axe is the second best after the sword.<br />
<br />
==Recipes==<br />
<br />
{|<br />
|+'''Crafting ingredients'''<br />
|-<br />
|Turtle<br />
|{{Crafting grid<br />
|A1=iron_ingot |B1=iron_ingot |C1=iron_ingot<br />
|A2=iron_ingot |B2=console |C2=iron_ingot<br />
|A3=iron_ingot |B3=chest |C3=iron_ingot<br />
|Output=turtle<br />
}}<br />
|-<br />
|Mining Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_pickaxe<br />
|Output=mining_turtle<br />
}}<br />
|-<br />
|Wireless Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=modem<br />
|Output=wireless_turtle<br />
}}<br />
|-<br />
|Wireless Mining Turtle<br />
|{{Crafting grid<br />
|A1=modem |B1=turtle |C1=diamond_pickaxe<br />
|Output=wireless_mining_turtle<br />
}}<br />
|}<br />
<br />
<br />
[[Category:Blocks]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Turtle&diff=2363Turtle2012-07-27T22:29:21Z<p>Pinkishu: </p>
<hr />
<div>'''Turtles''' are essentially robots, and were added in the 1.3 update. They run an OS (like the [[Console|consoles]]) named [[TurtleOS]]. They have the ability to place, break and detect blocks, move around and drop items in their inventory. The programs they run are stored on it's internal memory or [[Floppy Disk|floppy disks]].<br />
<br />
Turtles are submersible and lavaproof. As such, they are extremely useful for mining near bedrock, where heavy lava flows can prevent access to diamonds and other rare finds.<br />
<br />
If you would like to know more about how to program them, have a look at the [[Turtle (API)|Turtle API]].<br />
<br />
==Floppy Disks==<br />
Turtles do not have a built-in floppy drive. As such they need a floppy drive placed beside them to access disks. However if the turtle is a Wireless turtle, the floppy drive and other peripherals must be placed on a side other than the side the wireless modem is on.<br />
<br />
==Power source==<br />
Hardcore(default and added in 1.4):<br />
Turtles runs on fuel. Fuel is any item that works in a regular furnace, like coal and lava. The turtle gains 0.6 movement per half second the fuel would have burnt in a furnace.<br />
The turtle can move 1 block for each fuel count it got, for example, coal yields 96 block movements.<br />
<br />
Non Hardcore:<br />
Turtles have been equipped with a redstone engine, they do not need to be re-charged, or any other form of external power.<br />
This is because redstone continuously emits low levels of energy, and the turtle's engine is very efficient.<br />
==Farming==<br />
Turtles equipped with a hoe can till dirt.<br />
<br />
==Mining==<br />
Turtles crafted with a [[diamond pickaxe]], [[diamond axe]], [[diamond shovel]], can break blocks. The tools equipped on the turtle have no durability, and so can be used indefinitely without the need for any additional materials. When a turtle breaks the block it gets the item directly into its inventory. Different tools yields different drop, for example, an axe can break anything, but it won't get ores.<br />
<br />
==Crafting==<br />
Turtles equipped with a workbench can craft items. When crafting the upper left 3x3 part of the turtles inventory can only contain the items needed for the recipe.<br />
<br />
==Melee==<br />
Turtles equipped with a sword can attack players and mobs. When a turtle kills a mob it will leave the experience orbs on the ground, but add the loot to it's inventory. Turtles can also attack with any tool, where axe is the second best after the sword.<br />
<br />
==Recipes==<br />
<br />
{|<br />
|+'''Crafting ingredients'''<br />
|-<br />
|Turtle<br />
|{{Crafting grid<br />
|A1=iron_ingot |B1=iron_ingot |C1=iron_ingot<br />
|A2=iron_ingot |B2=console |C2=iron_ingot<br />
|A3=iron_ingot |B3=chest |C3=iron_ingot<br />
|Output=turtle<br />
}}<br />
|-<br />
|Mining Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=diamond_pickaxe<br />
|Output=mining_turtle<br />
}}<br />
|-<br />
|Wireless Turtle<br />
|{{Crafting grid<br />
|A2=turtle |B2=modem<br />
|Output=wireless_turtle<br />
}}<br />
|-<br />
|Wireless Mining Turtle<br />
|{{Crafting grid<br />
|A1=modem |B1=turtle |C1=diamond_pickaxe<br />
|Output=wireless_mining_turtle<br />
}}<br />
|}<br />
<br />
<br />
[[Category:Blocks]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2314Making a Password Protected Door2012-07-25T10:40:59Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
<br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term_(API)|term]].[[term.clear|clear]]()<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
if input == "password" then<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", true)<br />
[[sleep]](2)<br />
[[redstone_(API)|redstone]].[[redstone.setOutput|setOutput]]("back", false)<br />
end<br />
end<br />
<br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
[[Loops#The_While_loop|while]] true do <br />
[[term_(API)|term]].[[term.clear|clear]]() -- Clears the screen<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1) -- Fixes the cursor position<br />
[[write]]("Password: ") -- Prints 'Password: ' to the screen<br />
local input = [[read]]("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
[[term_(API)|term]].[[term.clear|clear]]() -- Already explained up top<br />
[[term_(API)|term]].[[term.setCursorPos|setCursorPos]](1,1)<br />
if input == password then -- Checks if the user inputted the correct password<br />
[[print]]("Password correct!") -- Prints 'Password correct!' to the screen<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,true) -- Output a redstone current to the side you specified<br />
[[sleep]](opentime) -- Wait the amount of seconds you specifed, then..<br />
[[redstone_(API)|rs]].[[redstone.setOutput|setOutput]](side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
[[print]]("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
[[sleep]](2) -- Waits 2 seconds<br />
end<br />
end<br />
<br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2313Making a Password Protected Door2012-07-25T10:36:07Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term.clear]]()<br />
[[term.setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
<br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<br />
[[Loops#The_While_loop|while]] true do<br />
[[term.clear]]()<br />
[[term.setCursorPos]](1, 1)<br />
[[print]]("Please Enter Password:")<br />
input = [[read]]("*")<br />
if input == "password" then<br />
[[redstone.setOutput]]("back", true)<br />
[[sleep]](2)<br />
[[redstone.setOutput]]("back", false)<br />
end<br />
end<br />
<br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
[[Loops#The_While_loop|while]] true do <br />
[[term.clear]]() -- Clears the screen<br />
[[term.setCursorPos]](1,1) -- Fixes the cursor position<br />
[[write]]("Password: ") -- Prints 'Password: ' to the screen<br />
local input = [[read]]("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
[[term.clear]]() -- Already explained up top<br />
[[term.setCursorPos]](1,1)<br />
if input == password then -- Checks if the user inputted the correct password<br />
[[print]]("Password correct!") -- Prints 'Password correct!' to the screen<br />
[[rs.setOutput]](side,true) -- Output a redstone current to the side you specified<br />
[[sleep]](opentime) -- Wait the amount of seconds you specifed, then..<br />
[[rs.setOutput]](side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
[[print]]("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
[[sleep]](2) -- Waits 2 seconds<br />
end<br />
end<br />
<br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2311Making a Password Protected Door2012-07-25T10:30:03Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<pre><br />
while true do<br />
term.clear()<br />
term.setCursorPos(1, 1)<br />
print("Please Enter Password:")<br />
input = read("*")<br />
</pre><br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<pre><br />
while true do<br />
term.clear()<br />
term.setCursorPos(1, 1)<br />
print("Please Enter Password:")<br />
input = read("*")<br />
if input == "password" then<br />
redstone.setOutput("back", true)<br />
sleep(2)<br />
redstone.setOutput("back", false)<br />
end<br />
end<br />
</pre><br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
<pre><br />
while true do<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
term.clear() -- Clears the screen<br />
term.setCursorPos(1,1) -- Fixes the cursor position<br />
write("Password: ") -- Prints 'Password: ' to the screen<br />
local input = read("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
term.clear() -- Already explained up top<br />
term.setCursorPos(1,1)<br />
if input == password then -- Checks if the user inputted the correct password<br />
print("Password correct!") -- Prints 'Password correct!' to the screen<br />
rs.setOutput(side,true) -- Output a redstone current to the side you specified<br />
sleep(opentime) -- Wait the amount of seconds you specifed, then..<br />
rs.setOutput(side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
print("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
sleep(2) -- Waits 2 seconds<br />
end<br />
end<br />
</pre><br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2310Making a Password Protected Door2012-07-25T10:28:57Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone. Like this:<br />
<br />
[[File:Tutorial1.png]]<br />
<br />
[[File:cTutorial2.png]]<br />
<br />
Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<pre><br />
while true do<br />
term.clear()<br />
term.setCursorPos(1, 1)<br />
print("Please Enter Password:")<br />
input = read("*")<br />
</pre><br />
<br />
The first line opens a loop that will continue running forever, or until we explicitly exit it with the 'break' keyword. The second and third lines clear the screen of whatever may have been on it, and then set the cursor position to the top-left corner of the screen. This ensures that each time the program loops, the text appears in the same place. The fifth line assigns whatever the user types to the variable 'input'. So for example, if I typed "qwerty", it would be assigning "qwerty" to the 'input' variable. In the read call on the third line ('read("*")'), the asterisk character will be used to replace each letter typed by the user, so that the password stays hidden.<br />
<br />
Here are the next few lines added on:<br />
<br />
<pre><br />
while true do<br />
term.clear()<br />
term.setCursorPos(1, 1)<br />
print("Please Enter Password:")<br />
input = read("*")<br />
if input == "password" then<br />
redstone.setOutput("back", true)<br />
sleep(2)<br />
redstone.setOutput("back", false)<br />
end<br />
end<br />
</pre><br />
<br />
The first line we add, 'if input == "password" then' checks whether or not the 'input' variable contains the string "password". The three lines immediately following are only executed if the password is correct. So if it's correct, 'redstone.setOutput("back", true)' sets the redstone output on the back side to true (on), which opens the door. The program then wait two seconds ('sleep(2)'), and turns the redstone output back off again. The program then reaches the end of the loop and repeats.<br />
<br />
Please note that this is the basic format for a computer protection program as well. We would put this program in the startup file and instead of outputting redstone signals if the password was correct, we would use the break keyword instead to exit the loop and allow access to the rest of the computer.<br />
<br />
Note also that if the program fails somehow, pressing and holding Ctrl + T will terminate it and allow you to edit it, see the [http://computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door#Stop_people_from_terminating_your_lock No termination section] to stop people from exiting your lock.<br />
<br />
= Alternative Code =<br />
<br />
Type 'edit startup' and type in this code: <br />
(Use Ctrl + T to terminate the program, all code is explained in the comments, the --'s. It's good to read the comments, so you actually know what the code does, you do not need to have the comments in your code, of course)<br />
<pre><br />
while true do<br />
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though<br />
local password = "bacon" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though<br />
local opentime = 5 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though<br />
term.clear() -- Clears the screen<br />
term.setCursorPos(1,1) -- Fixes the cursor position<br />
write("Password: ") -- Prints 'Password: ' to the screen<br />
local input = read("*") -- Makes the variable 'input' have the contents of what the user types in, the "*" part censors out the password<br />
term.clear() -- Already explained up top<br />
term.setCursorPos(1,1)<br />
if input == password then -- Checks if the user inputted the correct password<br />
print("Password correct!") -- Prints 'Password correct!' to the screen<br />
rs.setOutput(side,true) -- Output a redstone current to the side you specified<br />
sleep(opentime) -- Wait the amount of seconds you specifed, then..<br />
rs.setOutput(side,false) -- Stop outputting a redstone current<br />
else -- Checks if the user didn't input the correct password<br />
print("Password incorrect!") -- Prints 'Password incorrect!' to the screen<br />
sleep(2) -- Waits 2 seconds<br />
end<br />
end<br />
</pre><br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program:<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Making_a_Password_Protected_Door&diff=2290Making a Password Protected Door2012-07-24T14:34:10Z<p>Pinkishu: </p>
<hr />
<div><br />
This tutorial covers on how to make a computer output redstone current when the right password is typed in. The current is then used to trigger an iron door.<br />
<br />
<br />
__TOC__<br />
= How to make it =<br />
<br />
A password protected door is actually pretty easy, if you break it into steps.<br />
<br />
<br />
First, you need to craft a computer, and connect the back to an iron door with redstone, or just have a Computer next to the door.<br />
<br />
Once you're done with the basics, open the computer and edit the "startup" file. (type in 'edit startup')<br />
This will make it so the program will be executed when the computer boots.<br />
<br />
Once you access the startup file, enter in these five lines.<br />
<br />
<pre><br />
while true do<br />
print ("Enter Password")<br />
input = read()<br />
</pre><br />
<br />
The first line opens a loop that will continue running forever. The second lines "Prints" the message Enter Password on the screen. you can get rid of this if it's not wanted. The third line is used to change what the characters you type into the computer appear as. If you put ("*") after read, then it will appear in asterisks, While leaving it as is will show the password.<br />
<br />
Here are the next few lines added on:<br />
<br />
<pre><br />
while true do<br />
print ("Enter Password")<br />
input = read()<br />
if input == "password" then<br />
print ("Password Accepted")<br />
rs.setOutput("right", true)<br />
sleep()<br />
</pre><br />
<br />
The fourth line makes it so that if the word PASSWORD is typed, that it will go on to next steps. change the word "Password" to your desired password. The fifth line tells the computer to print Password Accepted if you correctly input the password. The sixth line outputs a redstone current on the given side. change "right" to the side you want to output a current. the seventh line tells the computer to halt the program for the given amount of time (Meaning it keeps door open for that amount of time)<br />
<br />
now, for the FINAL lines.<br />
<br />
<pre><br />
while true do<br />
print ("Enter Password")<br />
input = read()<br />
if input == "password" then<br />
print ("Password Accepted")<br />
rs.setOutput("right", true)<br />
sleep()<br />
rs.setOutput("right", false)<br />
else print ("Incorrect Password")<br />
end<br />
end<br />
</pre><br />
<br />
The eighth line turns OFF the redstone current on the line, thus closing the door. The ninth line indicates that if the password ISN'T correct, that it will print Incorrect Password. The final two lines end the program.<br />
<br />
= Stop people from terminating your lock =<br />
<br />
If you don't want people holding CTRL+T and quitting your lock, use this code at the top of your program (Note: This makes it so that you CANNOT access it by normal means):<br />
<pre>os.pullEvent = os.pullEventRaw</pre><br />
<br />
Okay, so now you want to CHANGE the program, but you can't. Here's the simple fix: Make a new computer and a disk drive. Get a floppy disk and put it in a disk drive that is adjacent to the new computer. Now, type in the computer<br />
edit disk/startup. this will make it so you can make it so it runs the disk's program on CPU startup. Now type in it print ("Hello World"). now save the program..... now, get that disk drive and put it NEXT to that computer. Then, put in the disk and enter the computer and do CTRL + R. the message "Hello World" should appear on the screen, allowing access to the startup file again.<br />
<br />
= Turning the password into asterisks =<br />
Replace the<br />
input = read()<br />
line with<br />
input = read("*")<br />
<br />
Now when you write your password it should show up as asterisks.<br />
<br />
<br />
<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Download&diff=2245Download2012-07-19T10:58:11Z<p>Pinkishu: Undo revision 2238 by 94.23.1.28 (talk)</p>
<hr />
<div>=== You can download the latest version of ComputerCraft [http://www.minecraftforum.net/topic/892282-11-computercraft-13/ here]. ===<br />
<br />
{{Changelog}}<br />
[[Category:Lists]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Tutorials&diff=2244Tutorials2012-07-19T10:57:54Z<p>Pinkishu: Undo revision 2237 by 94.23.1.28 (talk)</p>
<hr />
<div>As some tutorials might not be listed here, you can also browse the [[:Category:Tutorials|tutorials category]].<br />
<br />
== Before you begin ==<br />
It is recommended that you read these pages before you begin working with ComputerCraft.<br />
*[[Getting Started]]<br />
*[[CraftOS Shell | Shell Commands]]<br />
<br />
<br />
== Basic Tutorials ==<br />
These tutorials are designed to be used in the order shown, each tutorial will build on the previous ones.<br />
=== Introduction to Coding ===<br />
*[[Hello_World_Tutorial|Hello World!]]<br />
*[[Variables]]<br />
*[[Conditional_statements|If, Then, Else]]<br />
*[[Functions]]<br />
*[[Loops]]<br />
*[[Tables]]<br />
<br />
==Advanced tutorials==<br />
These tutorials deal with specific functions that are not always necessary, but may help improve your code considerably.<br />
===Coding for ComputerCraft===<br />
*[[Raw key events]]<br />
<br />
== Example Programs ==<br />
These pages guide you through programs created by other users. They are not necessarily well-coded, but can be useful as a loose guide.<br />
=== Programming & Wiring ===<br />
*[[Guess_The_Number_(tutorial)|Guess the Number]]<br />
*[[Making_a_Password_Protected_Door|Password Protected Door]]<br />
*[[Making_an_API_(tutorial)|Programming an API]]<br />
*[[Startup|Running script automatically at boot with Startup]]<br />
*[[Raw key events| Detecting specific keys (such as the arrow keys)]]<br />
*[[Receiving a rednet message through os.pullEvent()|Receiving a rednet message through os.pullEvent()]]<br />
*[[Calculator Tutorial]]<br />
*[[Rednet Tutorial]].<br />
<br />
=== Turtles ===<br />
The nice little robots that do the hard work for you.<br />
*[[Turtle_Tutorial|Turtles!]]<br />
*[[Turtle_Lumberjack_(tutorial)|Turtle Lumberjack]]<br />
*[[Advanced_Turtle_Lumberjack_(tutorial)|Advanced Turtle Lumberjack]]<br />
*[[Cobble_Generator|Cobblestone Generator]]<br />
*[[Turtle_Stairbuilder_(tutorial)|Turtle Stairbuilder]]<br />
<br />
== External Tutorials/Guides ==<br />
*[http://www.minecraftforum.net/topic/907632-mod-tutorial-computercraft-v12-very-basic-lua-tutorial-updated-1112/page__p__11556908#entry11556908 Onionnion's Basic Lua Tutorial]<br />
*[http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/page__view__findpost__p__11156 Onionnion's os.pullEvent() Guide]<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Tables&diff=2243Tables2012-07-19T10:57:20Z<p>Pinkishu: Undo revision 2236 by 188.143.232.12 (talk)</p>
<hr />
<div>[[Category:Tutorials]]<br />
This script will introduce you to tables, and show you some ways to use them.<br />
If you have experience with other languages, a table is roughly equivalent to an array.<br />
<br />
== Why are tables useful? ==<br />
<br />
Tables can simplify code considerably, by grouping like variables and functions together.<br />
<br />
In this example, we're getting a list of student's names<br />
Code without tables<br />
local StudentName1 = "Andrew"<br />
local StudentName2 = "Alfred"<br />
local StudentName3 = "Alex"<br />
local StudentName4 = "Amber"<br />
local StudentName5 = "Alice"<br />
<br />
Code with tables<br />
local StudentNames = {"Andrew", "Alfred", "Alex", "Amber", "Alice"}<br />
<br />
As you can see, the first example needs 5 unique variables being defined individually, while the second example, using the table, is all one line with one variable.<br />
<br />
Note the { and }, this is how you spot a table. Anything between them is a variable to be stored in the table. A table is not restricted to one variable type, and you can even store tables within tables if you wish<br />
<br />
== Using the table ==<br />
<br />
There are a number of ways to set the values in a table. The first, as shown above, is the simplest method, and will give each value a unique number as the "key". The key is simply the location in the table, it's usually a number or string. This method always clears the contents of the table and replaces it with what you've specified. Note that setting a table to "{}" is valid, and is commonly used if the values don't need to, or can't, be set immediately. You may find yourself using "Variable={}" often. Setting a specific key with this method is relatively simple, you just use the asignment operator "=" and treat the key as a variable<br />
local Table = {Key1 = "First key!", Key2 = "Second key!"}<br />
<br />
It can also be defined over multiple lines, to help with readability, if you end the line with a comma rather than the } to close it. Just remember to add the } when you're done.<br />
local Table = {"Stuff", 1, 2, "More stuff",<br />
3, "Some strings",<br />
function() end}<br />
<br />
Another method is to use brackets, [ and ], to specify the key. This method requires the table to have already been created, using { and }, otherwise it will give you an error. Using this method will treat it as a regular variable, so you can both set and read the value with this method. This method is commonly used for getting a value when the key is a number.<br />
local Table = {}<br />
Table["Boolean"] = true<br />
<br />
if Table["Boolean"] then print("The value is true!") end<br />
<br />
If you need to reference a table within a table using this method, you can simply add another [ ]<br />
<br />
local Table = {"Value", 2, {true, false}}<br />
<br />
if Table[3][2] then print("The value is true!") else print("The value is false!") end<br />
<br />
A third method is to simply add the key onto the end of the table name, separated by a ".". Like the previous method, this method requires the table to already exist. It can also be treated as a regular variable, as above. This method is commonly used for when the key is a string.<br />
local Table = {}<br />
<br />
Table.key = true<br />
if Table.key then print("True!") end<br />
<br />
As with the second method, to index a table within a table you just add the second key to the end. Note that these methods are interchangeable, and can all be used at the same time.<br />
<br />
It is not advisable to have many tables inside each other, especially if they are similarly named<br />
local Table = {String = "This is a string!", Table = {Number = 2, Table = {func = write, Table = {Bool = true} } }}<br />
<br />
if Table[Table].Table.Table.Bool then print("True!") end<br />
<br />
If you don't mind being restricted to number keys, you could use the table.insert(Table, [Position,] Value ) function.<br />
local Table = {"One"}<br />
table.insert(Table, "Three") --This inserts the string "Three" to the end of the table (At key 2)<br />
table.insert(Table, 2, "Two") --This inserts the string "Two" to key 2, pushing the string "Three" up to key three<br />
--End result, Table[1] is One, Table[2] is Two, Table[3] is Three<br />
<br />
== Tables and Loops ==<br />
<br />
When you combine tables and loops, they suddenly become a lot more useful. You can run through a table easily, using or changing each value.<br />
local Table = {"Hello! ", "This string ", "was read from ", "a table!", "\n"}<br />
for i=1,#Table do<br />
write( Table[i] )<br />
end<br />
This will write "Hello! This string was read from a table!" followed by a new line. You may notice there's a "#" behind Table, this simply returns the number of values in the table. It can also be used to get the length of a string.<br />
<br />
The standard for loop does, however, come with an inherent disadvantage in that it can only (easily) access consecutive numerical strings, ie 1,2,3 but not 1,2,4. to get around this, we can use "pairs" and "ipairs". "pairs" and "ipairs" use a table to loop, by running through the keys and values for the number that exist in the table.<br />
local Table = {StartTime = 0.5, EndTime = 1.5}<br />
<br />
for key,value in pairs( Table ) do<br />
print( tostring(key) ..": "..tostring(value))<br />
end<br />
This will output equivalent to "EndTime: 1.5\nStartTime: 0.5". Note that ipairs is identical to pairs, except it tries to do it in order.</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Getting_Started&diff=2242Getting Started2012-07-19T10:56:59Z<p>Pinkishu: Undo revision 2235 by 202.60.66.36 (talk)</p>
<hr />
<div>== Prerequisite: Installing the mods ==<br />
'''It is very important to read everything carefully before asking questions.'''<br />
'''Also, the latest version this mod may not be compatible with the current Minecraft release.'''<br />
<br />
# Install [http://www.minecraftforum.net/topic/75440- Risugami's ModLoader 1.2.5]<br />
# Install [http://lexmanos.no-ip.org:8080/job/Forge/Recommended/ Minecraft Forge Recommended Build 1.2.5]<br />
# Download the latest version of [http://www.minecraftforum.net/topic/892282- ComputerCraft 1.33 (1.2.5)]<br />
# Extract the .zip file in *minecraft folder*\mods\. (Tip: If on Windows, on the main screen of Minecraft, go to 'Texture Packs' and click on 'Open texture pack folder'. Go up one folder, there's your Minecraft folder. If on Mac, open Finder, hit Command+Shift+G and type ~/Library/ then hit enter, open 'Application Support' then open 'minecraft')<br />
<br />
== Step 1: Crafting the console ==<br />
The recipe is simple:<br /><br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=redstone |C2=stone<br />
|A3=stone |B3=glass pane |C3=stone<br />
|Output=console<br />
}}<br />
<br /><br />
<br />
Right click on the console to use it.<br /><br />
These are important to remember:<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Shortcut<br />
!style="background:#EEE" width="*"|Usage<br />
|-<br />
|CTRL + T<br />
|Closes the current program.<br />
|-<br />
|CTRL + R<br />
|Reboots the console.<br />
|-<br />
|CTRL + S<br />
|Forcefully shuts down the computer.<br />
|}<br />
NOTE: You have to hold the keyboard shortcuts down for at least 1 second!<br /><br />
These are forced and will close the current program, even if it is still running.<br />
<br />
== Step 2: Wiring it all up ==<br />
The console accepts many forms of redstone. For simple structures, such as a password protected door, only a single line of redstone is needed.<br />
However, this mod can do much more. If you need to connect multiple wires to one side, you can just use RedPower's cables. Easy peasy.<br />
Or, you don't do anything in this part. The computer has some great games shipped with and it is even capable of loading web pages.<br />
<br />
== Step 3: Programming your system ==<br />
If you've programmed before this shouldn't be hard. It'll feel very comfortable.<br />
<br />
Type<br />
edit <filename><br />
in the terminal to open the included feature-rich <!-- Save and exit!!! --> text editor. To get the hang of Lua if you're new, use<br />
edit /rom/programs/hello<br />
to view the code of a simple program 'hello'.<br />
<br />
Navigating is easy.<br />
> ls<br />
rom<br />
> cd rom<br />
rom> ls<br />
apis help programs<br />
startup<br />
rom> cd programs<br />
rom/programs> cd /<br />
><br />
To say it in English: ls '''l'''i'''s'''ts the files and folders in a directory, while cd changes the '''c'''urrent '''d'''irectory. / is the root of the computer.<br />
Again, you don't have to program, but it's a big part of the mod. But you can still play those games.<br />
<br />
== Step 4: Test it ==<br />
Make sure that your program is bug-proof before using it as something important. A system controlling the state of an IndustrialCraft² Mark-III Nuclear Reactor to prevent it from overheating shouldn't crash every now and then with "Too long without yielding".<br />
<br />
== Step 5: Extend it ==<br />
Give back your part to the community. Help others on the forums or improve the wiki. Or, make your own OS or shell to run on the computers and share it with everybody. You can even create your own peripheral blocks using the API to create even a bigger system. A mainframe, for example.</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Term_(API)&diff=2204Term (API)2012-07-18T14:20:39Z<p>Pinkishu: </p>
<hr />
<div>The Terminal API provides functions for ASCII graphics.<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[term.write|term.write( text )]]<br />
|Writes text to the screen.<br />
|-<br />
|[[term.clear|term.clear()]]<br />
|Clears the entire screen<br />
|-<br />
|[[term.clearLine|term.clearLine()]]<br />
|Clears the line the cursor is on<br />
|-<br />
|[[term.getCursorPos|term.getCursorPos()]]<br />
|Returns two arguments containing the x and the y position of the cursor.<br />
|-<br />
|[[Term.setCursorPos|term.setCursorPos( x, y )]]<br />
|Sets the cursor's position.<br />
|-<br />
|[[Term.setCursorBlink|term.setCursorBlink( b )]]<br />
|Disables the blinking or turns it on.<br />
|-<br />
|[[term.getSize|term.getSize()]]<br />
|Returns two arguments containing the x and the y values stating the size of the screen. (Good for if you're making something to be compatible with both [[Turtles]] and [[Consoles]].)<br />
|-<br />
|[[term.scroll|term.scroll( n )]]<br />
|Scrolls the terminal.<br />
|-<br />
|[[term.redirect|term.redirect( monitor )]]<br />
|Redirects terminal output to a monitor. (Use [[peripheral.wrap]] to acquire a monitor "object".)<br />
|-<br />
|[[term.restore|term.restore()]]<br />
|Restores terminal output to the console.<br />
|-<br />
|}<br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Term_(API)&diff=2203Term (API)2012-07-18T14:20:28Z<p>Pinkishu: </p>
<hr />
<div>The Terminal API provides functions for ASCII graphics.<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Method name<br />
!style="background:#EEE" width="*"|Description<br />
|-<br />
|[[term.write|term.write( text )]]<br />
|Writes text to the screen.<br />
|-<br />
|[[term.clear|term.clear()]]<br />
|Clears the entire screen<br />
|-<br />
|[[term.clearLine|term.clearLine()]]<br />
|Clears the line the cursor is on<br />
|-<br />
|[[term.getCursorPos|term.getCursorPos()]]<br />
|Returns two arguments containing the x and the y position of the cursor.<br />
|-<br />
|[[Term.setCursorPos|term.setCursorPos( x, y )]]<br />
|Sets the cursor's position.<br />
|-<br />
|[[Term.setCursorBlink|term.setCursorBlink( b )]]<br />
|Disables the blinking or turns it on.<br />
|-<br />
|[[term.getSize|term.getSize()]]<br />
|Returns two arguments containing the x and the y values stating the size of the screen. (Good for if you're making something to be compatible with both [[Turtles]] and [[Consoles]].)<br />
|-<br />
|[[term.scroll|term.scroll( n )]]<br />
|Scrolls the terminal.<br />
|-<br />
|[[term.redirect|term.redirect( monitor )]]<br />
|Redirects terminal output to a monitor. (Use [[peripheral.wrap]] to acquire a monitor object.)<br />
|-<br />
|[[term.restore|term.restore()]]<br />
|Restores terminal output to the console.<br />
|-<br />
|}<br />
[[Category:APIs]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Download&diff=2200Download2012-07-17T22:43:56Z<p>Pinkishu: Undo revision 2199 by 188.143.232.12 (talk)</p>
<hr />
<div>=== You can download the latest version of ComputerCraft [http://www.minecraftforum.net/topic/892282-11-computercraft-13/ here]. ===<br />
<br />
{{Changelog}}<br />
[[Category:Lists]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Tutorials&diff=2187Tutorials2012-07-17T15:24:08Z<p>Pinkishu: Undo revision 2186 by 177.81.1.177 (talk)</p>
<hr />
<div>As some tutorials might not be listed here, you can also browse the [[:Category:Tutorials|tutorials category]].<br />
<br />
== Before you begin ==<br />
It is recommended that you read these pages before you begin working with ComputerCraft.<br />
*[[Getting Started]]<br />
*[[CraftOS Shell | Shell Commands]]<br />
<br />
<br />
== Basic Tutorials ==<br />
These tutorials are designed to be used in the order shown, each tutorial will build on the previous ones.<br />
=== Introduction to Coding ===<br />
*[[Hello_World_Tutorial|Hello World!]]<br />
*[[Variables]]<br />
*[[Conditional_statements|If, Then, Else]]<br />
*[[Functions]]<br />
*[[Loops]]<br />
*[[Tables]]<br />
<br />
==Advanced tutorials==<br />
These tutorials deal with specific functions that are not always necessary, but may help improve your code considerably.<br />
===Coding for ComputerCraft===<br />
*[[Raw key events]]<br />
<br />
== Example Programs ==<br />
These pages guide you through programs created by other users. They are not necessarily well-coded, but can be useful as a loose guide.<br />
=== Programming & Wiring ===<br />
*[[Guess_The_Number_(tutorial)|Guess the Number]]<br />
*[[Making_a_Password_Protected_Door|Password Protected Door]]<br />
*[[Making_an_API_(tutorial)|Programming an API]]<br />
*[[Startup|Running script automatically at boot with Startup]]<br />
*[[Raw key events| Detecting specific keys (such as the arrow keys)]]<br />
*[[Receiving a rednet message through os.pullEvent()|Receiving a rednet message through os.pullEvent()]]<br />
*[[Calculator Tutorial]]<br />
*[[Rednet Tutorial]].<br />
<br />
=== Turtles ===<br />
The nice little robots that do the hard work for you.<br />
*[[Turtle_Tutorial|Turtles!]]<br />
*[[Turtle_Lumberjack_(tutorial)|Turtle Lumberjack]]<br />
*[[Advanced_Turtle_Lumberjack_(tutorial)|Advanced Turtle Lumberjack]]<br />
*[[Cobble_Generator|Cobblestone Generator]]<br />
*[[Turtle_Stairbuilder_(tutorial)|Turtle Stairbuilder]]<br />
<br />
== External Tutorials/Guides ==<br />
*[http://www.minecraftforum.net/topic/907632-mod-tutorial-computercraft-v12-very-basic-lua-tutorial-updated-1112/page__p__11556908#entry11556908 Onionnion's Basic Lua Tutorial]<br />
*[http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/page__view__findpost__p__11156 Onionnion's os.pullEvent() Guide]<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Receiving_a_rednet_message_through_os.pullEvent()&diff=2181Receiving a rednet message through os.pullEvent()2012-07-17T13:44:14Z<p>Pinkishu: </p>
<hr />
<div>The following method is a good method of receiving a rednet message without using rednet.receive().<br />
It is usually used in IRC, Chat programs e.t.c.<br />
When a message arrives to a computer, a "rednet_message" event occurs. <br />
== The Code ==<br />
This is a typical Listener which prints the content and the sender id of any incoming message.<br />
rednet.open("Direction_of_modem")<br />
while true do<br />
event, id, text = os.pullEvent()<br />
if event == "rednet_message" then<br />
print(id .. "> " .. text)<br />
end<br />
end<br />
<br />
== Explanation ==<br />
rednet.open("Direction_of_modem")<br />
Here we just open the modem.<br />
<br />
while true do<br />
We start a loop because os.pullEvent() terminates itself after 10 seconds.<br />
<br />
event, id, text = os.pullEvent()<br />
We wait for an event to occur and when this happens, we store the event's info into 3 variables.<br />
NOTE: You can give your variables whichever name you want.<br />
<br />
if event == "rednet_message" then<br />
We check if the event was a rednet message.<br />
<br />
print(id .. "> " .. text)<br />
We print the message and the id of the sender.<br />
<br />
end<br />
end<br />
We close our previous statements.</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Receiving_a_rednet_message_through_os.pullEvent()&diff=2180Receiving a rednet message through os.pullEvent()2012-07-17T13:43:57Z<p>Pinkishu: Undo revision 2179 by 188.143.232.12 (talk)</p>
<hr />
<div>The following method is a good method of receiving a rednet message without using rednet.receive().<br />
It is usually used in IRC, Chat programs e.t.c.<br />
When a message arrives to a computer, a "rednet_message" event occurs. <br />
== The Code ==<br />
This is a typical Listener which prints the content and the sender id of any incoming message.<br />
rednet.open("Direction_of_modem")<br />
while true do<br />
event, id, text = os.pullEvent()<br />
if event == "rednet_message" then<br />
print(id .. "> " .. text)<br />
end<br />
end<br />
<br />
== Explanation ==<br />
rednet.open("Direction_of_modem")<br />
Here we just open the modem.<br />
<br />
while true do<br />
We start a loop because os.pullEvent() terminates itself after 10 seconds.<br />
<br />
event, id, text = os.pullEvent()<br />
We wait for an event to occur and when this happens, we store the event's info into 3 variables.<br />
NOTE: You can give your variables whichever name you want.<br />
<br />
if event == "rednet_message" then<br />
We check if the event was a rednet message.<br />
<br />
print(id .. "> " .. text)<br />
We print the message and the id of the sender.<br />
<br />
end<br />
end<br />
We close our previous statements.<br />
<br />
<br />
Note: From my research, I didn't find a similar article and decided to make one. I hope that someone will improve it.<br />
--[[User:XDot|XDot]] 07:19, 17 April 2012 (UTC)</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Download&diff=2178Download2012-07-17T13:13:24Z<p>Pinkishu: Undo revision 2173 by 163.225.233.220 (talk)</p>
<hr />
<div>=== You can download the latest version of ComputerCraft [http://www.minecraftforum.net/topic/892282-11-computercraft-13/ here]. ===<br />
<br />
{{Changelog}}<br />
[[Category:Lists]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Tables&diff=2177Tables2012-07-17T13:12:49Z<p>Pinkishu: Undo revision 2172 by 212.142.46.129 (talk)</p>
<hr />
<div>[[Category:Tutorials]]<br />
This script will introduce you to tables, and show you some ways to use them.<br />
If you have experience with other languages, a table is roughly equivalent to an array.<br />
<br />
Wow! Great to find a post with such a clear maesgse!<br />
<br />
== Using the table ==<br />
<br />
There are a number of ways to set the values in a table. The first, as shown above, is the simplest method, and will give each value a unique number as the "key". The key is simply the location in the table, it's usually a number or string. This method always clears the contents of the table and replaces it with what you've specified. Note that setting a table to "{}" is valid, and is commonly used if the values don't need to, or can't, be set immediately. You may find yourself using "Variable={}" often. Setting a specific key with this method is relatively simple, you just use the asignment operator "=" and treat the key as a variable<br />
local Table = {Key1 = "First key!", Key2 = "Second key!"}<br />
<br />
It can also be defined over multiple lines, to help with readability, if you end the line with a comma rather than the } to close it. Just remember to add the } when you're done.<br />
local Table = {"Stuff", 1, 2, "More stuff",<br />
3, "Some strings",<br />
function() end}<br />
<br />
Another method is to use brackets, [ and ], to specify the key. This method requires the table to have already been created, using { and }, otherwise it will give you an error. Using this method will treat it as a regular variable, so you can both set and read the value with this method. This method is commonly used for getting a value when the key is a number.<br />
local Table = {}<br />
Table["Boolean"] = true<br />
<br />
if Table["Boolean"] then print("The value is true!") end<br />
<br />
If you need to reference a table within a table using this method, you can simply add another [ ]<br />
<br />
local Table = {"Value", 2, {true, false}}<br />
<br />
if Table[3][2] then print("The value is true!") else print("The value is false!") end<br />
<br />
A third method is to simply add the key onto the end of the table name, separated by a ".". Like the previous method, this method requires the table to already exist. It can also be treated as a regular variable, as above. This method is commonly used for when the key is a string.<br />
local Table = {}<br />
<br />
Table.key = true<br />
if Table.key then print("True!") end<br />
<br />
As with the second method, to index a table within a table you just add the second key to the end. Note that these methods are interchangeable, and can all be used at the same time.<br />
<br />
It is not advisable to have many tables inside each other, especially if they are similarly named<br />
local Table = {String = "This is a string!", Table = {Number = 2, Table = {func = write, Table = {Bool = true} } }}<br />
<br />
if Table[Table].Table.Table.Bool then print("True!") end<br />
<br />
If you don't mind being restricted to number keys, you could use the table.insert(Table, [Position,] Value ) function.<br />
local Table = {"One"}<br />
table.insert(Table, "Three") --This inserts the string "Three" to the end of the table (At key 2)<br />
table.insert(Table, 2, "Two") --This inserts the string "Two" to key 2, pushing the string "Three" up to key three<br />
--End result, Table[1] is One, Table[2] is Two, Table[3] is Three<br />
<br />
== Tables and Loops ==<br />
<br />
When you combine tables and loops, they suddenly become a lot more useful. You can run through a table easily, using or changing each value.<br />
local Table = {"Hello! ", "This string ", "was read from ", "a table!", "\n"}<br />
for i=1,#Table do<br />
write( Table[i] )<br />
end<br />
This will write "Hello! This string was read from a table!" followed by a new line. You may notice there's a "#" behind Table, this simply returns the number of values in the table. It can also be used to get the length of a string.<br />
<br />
The standard for loop does, however, come with an inherent disadvantage in that it can only (easily) access consecutive numerical strings, ie 1,2,3 but not 1,2,4. to get around this, we can use "pairs" and "ipairs". "pairs" and "ipairs" use a table to loop, by running through the keys and values for the number that exist in the table.<br />
local Table = {StartTime = 0.5, EndTime = 1.5}<br />
<br />
for key,value in pairs( Table ) do<br />
print( tostring(key) ..": "..tostring(value))<br />
end<br />
This will output equivalent to "EndTime: 1.5\nStartTime: 0.5". Note that ipairs is identical to pairs, except it tries to do it in order.</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Tutorials&diff=2176Tutorials2012-07-17T13:12:38Z<p>Pinkishu: Undo revision 2171 by 126.117.226.163 (talk)</p>
<hr />
<div>As some tutorials might not be listed here, you can also browse the [[:Category:Tutorials|tutorials category]].<br />
<br />
== Before you begin ==<br />
It is recommended that you read these pages before you begin working with ComputerCraft.<br />
*[[Getting Started]]<br />
*[[CraftOS Shell | Shell Commands]]<br />
<br />
<br />
== Basic Tutorials ==<br />
These tutorials are designed to be used in the order shown, each tutorial will build on the previous ones.<br />
=== Introduction to Coding ===<br />
*[[Hello_World_Tutorial|Hello World!]]<br />
*[[Variables]]<br />
*[[Conditional_statements|If, Then, Else]]<br />
*[[Functions]]<br />
*[[Loops]]<br />
*[[Tables]]<br />
<br />
==Advanced tutorials==<br />
These tutorials deal with specific functions that are not always necessary, but may help improve your code considerably.<br />
===Coding for ComputerCraft===<br />
*[[Raw key events]]<br />
<br />
== Example Programs ==<br />
These pages guide you through programs created by other users. They are not necessarily well-coded, but can be useful as a loose guide.<br />
=== Programming & Wiring ===<br />
*[[Guess_The_Number_(tutorial)|Guess the Number]]<br />
*[[Making_a_Password_Protected_Door|Password Protected Door]]<br />
*[[Making_an_API_(tutorial)|Programming an API]]<br />
*[[Startup|Running script automatically at boot with Startup]]<br />
*[[Raw key events| Detecting specific keys (such as the arrow keys)]]<br />
*[[Receiving a rednet message through os.pullEvent()|Receiving a rednet message through os.pullEvent()]]<br />
*[[Calculator Tutorial]]<br />
*[[Rednet Tutorial]].<br />
<br />
=== Turtles ===<br />
The nice little robots that do the hard work for you.<br />
*[[Turtle_Tutorial|Turtles!]]<br />
*[[Turtle_Lumberjack_(tutorial)|Turtle Lumberjack]]<br />
*[[Advanced_Turtle_Lumberjack_(tutorial)|Advanced Turtle Lumberjack]]<br />
*[[Cobble_Generator|Cobblestone Generator]]<br />
*[[Turtle_Stairbuilder_(tutorial)|Turtle Stairbuilder]]<br />
<br />
== External Tutorials/Guides ==<br />
*[http://www.minecraftforum.net/topic/907632-mod-tutorial-computercraft-v12-very-basic-lua-tutorial-updated-1112/page__p__11556908#entry11556908 Onionnion's Basic Lua Tutorial]<br />
*[http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/page__view__findpost__p__11156 Onionnion's os.pullEvent() Guide]<br />
<br />
[[Category:Tutorials]]</div>Pinkishuhttp://www.computercraft.info/wiki/index.php?title=Getting_Started&diff=2175Getting Started2012-07-17T13:11:51Z<p>Pinkishu: Undo revision 2165 by 98.175.6.158 (talk)</p>
<hr />
<div>== Prerequisite: Installing the mods ==<br />
'''It is very important to read everything carefully before asking questions.'''<br />
'''Also, the latest version this mod may not be compatible with the current Minecraft release.'''<br />
<br />
# Install [http://www.minecraftforum.net/topic/75440- Risugami's ModLoader 1.2.5]<br />
# Install [http://lexmanos.no-ip.org:8080/job/Forge/Recommended/ Minecraft Forge Recommended Build 1.2.5]<br />
# Download the latest version of [http://www.minecraftforum.net/topic/892282- ComputerCraft 1.33 (1.2.5)]<br />
# Extract the .zip file in *minecraft folder*\mods\. (Tip: If on Windows, on the main screen of Minecraft, go to 'Texture Packs' and click on 'Open texture pack folder'. Go up one folder, there's your Minecraft folder. If on Mac, open Finder, hit Command+Shift+G and type ~/Library/ then hit enter, open 'Application Support' then open 'minecraft')<br />
<br />
== Step 1: Crafting the console ==<br />
The recipe is simple:<br /><br />
{{Crafting grid<br />
|A1=stone |B1=stone |C1=stone<br />
|A2=stone |B2=redstone |C2=stone<br />
|A3=stone |B3=glass pane |C3=stone<br />
|Output=console<br />
}}<br />
<br /><br />
<br />
Right click on the console to use it.<br /><br />
These are important to remember:<br />
{| border="1" cellpadding="2" cellspacing="0"<br />
!style="background:#EEE" width="200px"|Shortcut<br />
!style="background:#EEE" width="*"|Usage<br />
|-<br />
|CTRL + T<br />
|Closes the current program.<br />
|-<br />
|CTRL + R<br />
|Reboots the console.<br />
|-<br />
|CTRL + S<br />
|Forcefully shuts down the computer.<br />
|}<br />
NOTE: You have to hold the keyboard shortcuts down for at least 1 second!<br /><br />
These are forced and will close the current program, even if it is still running.<br />
<br />
== Step 2: Wiring it all up ==<br />
The console accepts many forms of redstone. For simple structures, such as a password protected door, only a single line of redstone is needed.<br />
However, this mod can do much more. If you need to connect multiple wires to one side, you can just use RedPower's cables. Easy peasy.<br />
Or, you don't do anything in this part. The computer has some great games shipped with and it is even capable of loading web pages.<br />
<br />
== Step 3: Programming your system ==<br />
If you've programmed before this shouldn't be hard. It'll feel very comfortable.<br />
<br />
Type<br />
edit <filename><br />
in the terminal to open the included feature-rich <!-- Save and exit!!! --> text editor. To get the hang of Lua if you're new, use<br />
edit /rom/programs/hello<br />
to view the code of a simple program 'hello'.<br />
<br />
Navigating is easy.<br />
> ls<br />
rom<br />
> cd rom<br />
rom> ls<br />
apis help programs<br />
startup<br />
rom> cd programs<br />
rom/programs> cd /<br />
><br />
To say it in English: ls '''l'''i'''s'''ts the files and folders in a directory, while cd changes the '''c'''urrent '''d'''irectory. / is the root of the computer.<br />
Again, you don't have to program, but it's a big part of the mod. But you can still play those games.<br />
<br />
== Step 4: Test it ==<br />
Make sure that your program is bug-proof before using it as something important. A system controlling the state of an IndustrialCraft² Mark-III Nuclear Reactor to prevent it from overheating shouldn't crash every now and then with "Too long without yielding".<br />
<br />
== Step 5: Extend it ==<br />
Give back your part to the community. Help others on the forums or improve the wiki. Or, make your own OS or shell to run on the computers and share it with everybody. You can even create your own peripheral blocks using the API to create even a bigger system. A mainframe, for example.</div>Pinkishu