Jump to content




Roomdigger


7 replies to this topic

#1 Kurald

  • New Members
  • 2 posts

Posted 14 March 2012 - 08:13 PM

Hi,

here's my first try of a room digging script. I will update it in the future.
The script will dig a cuboid room of depth, height and width size.


local tArgs = { ... }
-- check number of arguments
if #tArgs < 3 or #tArgs > 4 then
error("Usage: room <depth> <height> <width>")
end

depth = tonumber(tArgs[1])
height = tonumber(tArgs[2])
width = tonumber(tArgs[3])

print("Digging Room D"..tArgs[1].."xH"..tArgs[2].."xW"..tArgs[3]);
-- move forward to create room
turtle.dig()
turtle.forward()
-- adjust depth for the step
depth = depth - 1
-- create room
for widthTemp = 1, width do
for heightTemp = 1, height do
for depthTemp = 1, depth do
-- dig straight forward
while turtle.detect() do
turtle.dig()
os.sleep(1) -- needed to work with gravel
end
turtle.forward()
		end
		-- line complete, move to next line
		if heightTemp<height then
while turtle.detectUp() do
turtle.digUp()
end
			turtle.up()
			turtle.turnLeft()
			turtle.turnLeft()
end
end
	-- slice complete, return to start
	-- move back on odd heights, otherwise we are already back
	if height % 2 == 1 then
		turtle.turnLeft()
		turtle.turnLeft()
		for depthTemp=1, depth do
			turtle.forward()
            os.sleep(1)
		end
	end
	-- move down
	for heightTemp=0, height-1 do
		turtle.down()
end
	-- next slice
	if widthTemp<width then
		turtle.turnLeft()
while turtle.detect() do
turtle.dig()
end
		turtle.forward()
		turtle.turnLeft()
	end
end

Options for the future:
  • make api function with parameters for height, width, ...
  • allow turtle to be placed in lower right corner instead of lower left
  • place walls if needed.
  • added support for gravel


#2 Kurald

  • New Members
  • 2 posts

Posted 14 March 2012 - 09:45 PM

updated script to use parameters, added support for gravel

Support for gravel:

while turtle.detect() do
  turtle.dig()
end

is the base for digging away gravel. When moving forward, an os.sleep(1) needs to be inserted to wait until the gravel has set - otherwise detect will fail. This is not necessary for digging up since then the gravel is already gone.

#3 littlejamo

  • New Members
  • 2 posts

Posted 17 February 2013 - 04:28 AM

Pastebin it ?

#4 unobtanium

  • Members
  • 505 posts

Posted 18 February 2013 - 05:02 AM

This thread is older then myself ;D

Last Active Mar 15 2012 06:26 AM
I dont think he is comming back and make a pastebinlink. However you can do it on your own if ya want to.

#5 Minithra

  • Members
  • 25 posts

Posted 18 February 2013 - 07:24 AM

Gravel breaks this. Well, not break... you just get piles of gravel in the room. Since it digs from the bottom up, the gravel that falls when it's digging the higher layers of the room falls to the floor and is not destroyed. Not a big problem, though.

#6 alanaktion

  • New Members
  • 1 posts

Posted 09 March 2013 - 02:08 PM

Hey, I posted this to Pastebin for anyone who wants to use it in-game more easily.

http://pastebin.com/QeuSu0XU

From turtle:
pastebin get QeuSu0XU roomdigger

#7 Altentio

  • Members
  • 4 posts

Posted 18 March 2013 - 09:15 PM

i think it would be wiser (in terms of fuel) to have it start from 1 height above, and make it dig not only front but also up and down, that way you save on fuel (just a suggestion, when you feel like improving your code) . Other than that using it currently, feels nice, thanks a lot =)

#8 luochen1990

  • Members
  • 31 posts

Posted 18 March 2013 - 11:15 PM

I had written an recursive one which can dig all continuous specified blocks . it's independent from the shape of what you dig. but because of the limit for a new user. I have to post at least 3 times before I can start a new topic... :(





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users