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

Tunnel Lighter

Started by 6677, 26 February 2012 - 03:32 PM
6677 #1
Posted 26 February 2012 - 04:32 PM
Quick script I wrote last night.
Works with either glowstone or torches with a different mode for each. Will work with redstone lamps, redpower lights and so on aswell (hence why parameter is block not glowstone)
Simply run:

lightup 200 torch
to place torches evenly down a 200 block tunnel, don't worry if the tunnel is shorter it will detect the obstruction and stop. sub torch for block to place blocks instead.
The turtle must be placed on the floor of the tunnel facing the right direction.

Code:

tArgs = { ... }
if (#tArgs ~= 2) or (tonumber(tArgs[1]) < 8) or (((tArgs[2] == "torch")or(tArgs[2] == "block")) == false) then
print("Usage: lightup <distance> <torch/block>")
print("Light Source Must Be Placed In Slot 9")
if tonumber(tArgs[1]) < 8 then
	 print("Distance must be greater than 8")
    end
    if (((tArgs[2] == "torch")or(tArgs[2] == "glowstone")) == false) then
	    print(tArgs[2])
	    print("Must enter torch or glowstone")
    end
return
end
turtle.select(9)   
distance = tonumber(tArgs[1])
if turtle.getItemCount(9) < 1 then
    print("No torches left")
    distance = 0
end
if tArgs[2] == "torch" then
    turtle.up()
end
while distance > 8 do
    for y = 1, 8 do
	    if turtle.forward() == true then
		    distance = distance - 1
	    else
		    print("Obstruction Hit")
		    distance = 0
	    end
    end
    if turtle.getItemCount(9) < 1 then
	    print("No torches left")
	    distance = 0
    else
	    turtle.digDown()
	    turtle.placeDown()
    end
end
if tArgs[2] == "torch" then
    turtle.down()
end


Its not great but it works, blocks it automatically digs a hole in the floor and places them.

The light sources go in slot 9 (which it says in the program)
Might update it to dig the tunnels aswell.
panicmore #2
Posted 26 February 2012 - 06:10 PM
mine does this but it will do it infinetly down the tunnel
6677 #3
Posted 27 February 2012 - 11:18 AM
mine does this but it will do it infinetly down the tunnel
Does yours handle blocks and torches seperately?
I didn't want mine to go infinitely.

I've added a parameter for spacing, will post update tommorow (laptop with the new code is at home)
panicmore #4
Posted 27 February 2012 - 09:38 PM
Didn't mean to offend