This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Uncreative_Name's profile picture

Basic Programs [Tunneller, Staircase Creator and More]

Started by Uncreative_Name, 03 March 2012 - 07:07 PM
Uncreative_Name #1
Posted 03 March 2012 - 08:07 PM
Turtle

Here is a collection of some very basic programs for the Turtle.


Tunneller [http://pastebin.com/rtN5irdB]
The Tunneller digs out a 1 x 2 Tunnel however long the user decides. It additionally places torches at a user inputted frequency and places a block beneath it should it dig above a lava pool. All the while the turtle tracks and prints out it's progress.

Spoiler

local digsleft = 0
local maxdigs = 0
local digs = 0
local torchtime = 0
local maxtt = 0
local torches = 0
local gaps = 0
function graveldetect()
if turtle.detect() then
turtle.dig()
end
if turtle.detect() then
turtle.dig()
end
if turtle.detect() then
turtle.dig()
end
if turtle.detect() then
turtle.dig()
end
end
-- End of functions and variables.
term.clear()
term.setCursorPos(1,1)
print("Place some building material in slot one, and torches in slot nine.")
sleep(3)
print("How many blocks long would you like your tunnel? ")
maxdigs = tonumber(io.read())
print("How often should I place torches? ")
maxtt = tonumber(io.read())
term.clear()
term.setCursorPos(1,1)
digsleft = maxdigs
while true do
term.clear()
term.setCursorPos(1,1)
print("Turtle will dig "..digsleft.." more blocks.")
print("Turtle has bridged "..gaps.." gaps.")
print("Turtle has placed "..torches.." torches.")
if turtle.getItemCount(1) == 0 then
term.clear()
term.setCursorPos(1,1)
print("Turtle requires building material in slot one.")
break
else
end
if turtle.getItemCount(9) == 0 then
term.clear()
term.setCursorPos(1,1)
print("Turtle requires torches in slot nine.")
break
else
end
if turtle.detectUp() then
term.clear()
term.setCursorPos(1,1)
print("Unexpected Obstruction... Stopping Operation.")
break
else
end
if not turtle.detectDown() then
turtle.select(1)
turtle.placeDown()
gaps = gaps + 1
end
turtle.dig()
graveldetect()
turtle.up()
graveldetect()
torchtime = torchtime + 1
if torchtime == maxtt then
turtle.select(9)
turtle.back()
turtle.placeDown()
turtle.forward()
torchtime = 0
torches = torches + 1
else
end
turtle.down()
turtle.forward()
digs = digs + 1
digsleft = digsleft - 1
if digs == maxdigs then
print("Tunnel Operation Complete")
break
else
end
end



Flint Maker
The Flint Maker is very basic, simply insert gravel into slot one and the Turtle will dig until all the gravel is expended.

Spoiler


print("Making Gravel into Flint")
print("Press Control + T to stop.")
turtle.select(1)
while true do
turtle.place()
if turtle.detect() then
turtle.dig()
else
print("Gravel Supply Expended")
break
end
end

Item Disposals
Another simple program, this will simply dig a hole, drop it's inventory and then fill the hole in afterwards.

Spoiler


print("Dropping Items...")
turtle.digDown()
turtle.down()
turtle.select(1)
turtle.drop()
turtle.digDown()
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
turtle.select(5)
turtle.drop()
turtle.select(6)
turtle.drop()
turtle.select(7)
turtle.drop()
turtle.select(8)
turtle.drop()
turtle.select(9)
turtle.drop()
turtle.up()
turtle.select(1)
turtle.placeDown()
print("Items Dropped")

Staircase Creator
The Staircase Creator will create a very easy to descend staircase, like the Tunneller the depth is user inputted.


Spoiler


local maxdigs = 0
local digs = 0

print("How deep would you like your staircase?")
maxdigs = tonumber(io.read())
digsleft = maxdigs


while true do
term.clear()
term.setCursorPos(1,1)
print("Turtle will descend "..digsleft.." more blocks.")
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.back()
turtle.back()
digsleft = digsleft - 1
digs = digs + 1
if digs == maxdigs then
break
else
end
end


Terminal

Advanced Doorlock

An advanced doorlock with a linear or exponentially increasing delay.

Spoiler


function clres()
term.clear()
term.setCursorPos(1,1)
end

local terminalpassword = "debug"
local password = "password"
local delay = 3
local permdelay = 3
local increase = 3
exponential = false

if exponential == true and delay == 1 then
delay = 2
end

clres()


while true do
clres()
if delay ~= permdelay then
print("Program incorrectly configured.")
end
print("Enter your password: ")
if delay ~= permdelay then
term.setCursorPos(22,2)
else
term.setCursorPos(22,1)
end
userinput = io.read()
if userinput == password then
print("Correct. Opening Door.")
redstone.setOutput("left", true)
sleep(3)
redstone.setOutput("left", false)
elseif userinput == terminalpassword then
clres()
print(os.version())
print("Make sure you shutdown your terminal to be fully secured.")
break
else
clres()
print("Incorrect. Please wait "..delay.." seconds and try again.")
clres()
sleep(delay)
if exponential == false then
delay = delay + increase
end
if exponential == true then
delay = delay * 2
end
end
end



Random Number Generator
Spoiler


while true do
term.clear()
term.setCursorPos(1,1)
print("Enter two numbers to get a random number between the two.")
term.setCursorPos(1,3)
print("Low number: ")
print("High number: ")
term.setCursorPos(13,3)
firstnumber = tonumber(io.read())
term.setCursorPos(14,4)
secondnumber = tonumber(io.read())
if secondnumber < firstnumber then
print("That number is too damn high!")
sleep(3)
break
end
if secondnumber == firstnumber then
print("Cheater!")
sleep(3)
break
end
if firstnumber > 100000000 then
print("That number will hurt my brain.")
sleep(3)
break
end
if secondnumber > 100000000 then
print("That number will hurt my brain.")
sleep(3)
break
end
if firstnumber < secondnumber then
print(math.random(firstnumber,secondnumber))
break
end
end


Dice
Spoiler


term.clear()
term.setCursorPos(1,1)
print("Rolling...")
while true do
term.setCursorPos(1,2)
term.clearLine()
print(math.random(1,6))
sleep(0.1)
if math.random(1,25) == 1 then
break
end
end
Uncreative_Name #2
Posted 04 March 2012 - 06:54 AM
March 3rd - 11:00 PM

ADDED:
  • ​Dice
  • Random Numer Generator
FIXED:
  • Many assorted fixes
Zer0t3ch #3
Posted 13 March 2012 - 08:16 PM
Looks good. I'm probably going to download the flint one and the disposal one for my server later.
Temploit #4
Posted 18 March 2012 - 01:07 PM
You can shorten the Item Disposals code by making a loop:


print("Dropping Items…")
turtle.digDown()
turtle.down()
turtle.digDown()
turtle.down()
for i=1,9 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
turtle.digDown()
turtle.up()
turtle.up()
turtle.placeDown()
print("Items Dropped")
Ian-Moone #5
Posted 21 March 2012 - 12:19 PM
defiantly getting the flint one
will save so mush time for my friends