Technic Pack Wiki
Register
Advertisement
Logo CC 40 Code Snippets contains information about the ComputerCraft mod.
Logo pickaxe The article Code Snippets is still unfinished and may be lacking detailed general information, screenshots, and crafting recipes. Please expand the article and remove the {{unfinished}} tag once the article can be considered complete.

Code Snippets to be used with Computer Craft

Digging forward (for any kind of turtle):[]

Version 1

while turtle.detect() do -- detect if something is in front
    turtle.dig() -- dig it away
    os.sleep(1) -- wait for falling [item] to settle ; "sleep" means do nothing 
                -- and wait an amount of time, defined in those brackets "(X)"
end
turtle.forward() -- move forward

Alternate Version:

while not turtle.forward() do -- move forward. If it did not work, do the rest
    turtle.dig() -- something must have been in front, dig it away
    os.sleep(0.1) -- sleep for 0.1 seconds
end
reboot

Passcode Protected Doors :[]

This is a tutorial on how to create a passcode protected door. Build a Computer and put it next to an Iron Door

2012-09-06 16.40

This is how it should look









Step 1:

type this into your computer:

edit startup

Step 2:

Read the things after the "--"

os.pullEvent = os.pullEventRaw -- this prevents the user from holding CTRL+T
print("Password Please!")
write("\nPasscode >> ") -- the \n makes a newline
local doorSide = "Change this to the side your door is on"
local passcode = "My Password" -- change to whatever you want the passcode to b
local entered = read("*") -- You can change the * to any charecter you want
local useComp = false -- Disable usage of the computer
if(entered==passcode)then -- detects if you entered the correct passcode
  print("\nPasscode Accepted")
  redstone.setOutput(doorSide, true) --Send a signal to open the door
  sleep(3) -- The computer will do nothing for 3 seconds.
  redstone.setOutput(doorSide, true) --Send a signal again, but closes the door
  local useComp = true -- You will be able to use the compuer if you enter the passcode, change to false if you don't want that
end
if(useComp)then
  os.reboot
end

When your done typing this, press CTRL, then press S (that's how you save) then press CTRL then E (to exit)

Now press and hold CTRL+R for 1 second to reboot, or you can just type "reboot"

Another Way (not as secure):[]

Step 1:

 edit startup

Step 2:

print("Password Please!")

Step 3:

edit [YOUR PASSWORD HERE]

Step 4 assumes the door is to the left of the computer (change "left" in the code as necessary):

print("Password Correct!")                   
    redstone.setOutput("left", true)  
    os.sleep(6)
    redstone.setOuput("left", false)
    os.reboot()

If you had any problems with this last part, such as receiving errors, post it in the comments and someone will help you out.

Step 5: You're done!!!!!!!!!

2012-09-06 16.41

What the computer will say

Step 6 (optional): This step is usually used on multiplayer servers. If you do not want people hacking into your computer, there are simple steps to prevent this. One thing that they will do is use the edit command. To prevent this, just type in

   edit edit
   print("No Hacking!")


Step 7 (optional): Like step 6 People can still hack into your computer... Some hackers just delete the startup, to fix this just type

   edit rm
   print("No Hacking!")

And you're done! Hackers cannot hack. Another thing they might do is use lua, the main coding system, so just repeat the steps but edit the lua command instead.

How To Create an Override Mode for Your Door This will unlock a computer-controlled door and leave it open until the computer is rebooted. Step 1:

edit [override password]

Step 2:

print("Override Mode Accepted. Reboot once done...")
redstone.setOutput("left",true)

When you're done overriding the door lock, reboot the door computer to turn off its redstone signal:

reboot
Advertisement