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

(LUA) trying to make a quarry system

Started by Mordlin, 28 October 2012 - 02:35 AM
Mordlin #1
Posted 28 October 2012 - 03:35 AM
Hello, I have recently downloaded tekkit and I am currently enjoying computer craft in the server I am on,

I have taken a great interest in the turtles and would like to be able to set up some things, but with out knowing programming I feel I may be over my head.

The server I am on has a pastebin support so I can easily load programs into my turtles. I have attempted to run Pooslice's http://www.computerc...-clear-a-chunk/

but I do not think the server I am on has the correct version of computer craft to run even the first version of the program.

So i have started to write my own code from some of the basic commands on the wiki, but I have no idea if it would work. and there is a lot more that I would like to do but have no clue how to.

I currently have the code here http://pastebin.com/yG5fE9Vv. and the basic idea is I set a turtle next to a disk drive and he will go forward 1 block turn his reednet on and then walk 16 blocks to the left. I would like to be able to put 16 turtles down and have them all line up in this fashion.

Next I have them dig one block down and place a chest above them, so as they are digging their lines if they fill up they can drop their stuff off.

I have no idea if i am even close to being able to do this, and thanks in advance for any help.
ChunLing #2
Posted 28 October 2012 - 04:57 AM
Tekkit does not have the latest version of ComputerCraft, so a lot of the commands in the wiki won't work, particularly your inventory interaction commands.

However, the use of a startup disk in a disk drive is feasible, and your program looks like it should work. There are some things you can do to tighten it up, though.
turtle.forward()

rednet.open("right") --wireless turtles typically have their rednet on the right, so this is the only command you need
for i = 1,16 do turtle.forward() end --for loops are your friends
turtle.turnRight()
turtle.digDown()
turtle.down() --you may want a turtle.down() here, if I understand what you're trying.
turtle.select(1)
turtle.placeUp()
for i = 1,16 do turtle.dig() turtle.forward end --you need to move after each dig, or you'll be trying to dig air
turtle.turnLeft()
turtle.turnLeft()
turtle.digDown()
You'll need to use pipes and stuff to collect inventory drops rather than interacting directly with chests. This should not be a problem if you have tekkit.
remiX #3
Posted 28 October 2012 - 05:03 AM
Not quite sure exactly what you want but this code basically at first, moves 1 forward, then turns left and then moves forward, digs down and place an item above itself - 16 times.

side = "left"
rednet.open(side)

turtle.forward()
turtle.turnLeft()
turtle.select(1)
for i = 1,16 do
    while turtle.detect() then turtle.dig() end
    turtle.forward()
    turtle.digDown()
    turtle.placeUp()
end
Mordlin #4
Posted 28 October 2012 - 05:23 AM
okay With those loops it really cuts down on the code.

so now i have


for i = 1,16 do turtle.dig() turtle.forward()
end

turtle.digDown()
turtle.down()
turtle.turnRight()
turtle.turnRight()

for i = 1,16 do turtle.dig() turtle.forward()
end

This should make the turtle dig and move 16 blocks forward then dig down and turn around 180 degrees and dig back correct?

And now if I wanted to hook up more than one turtle to this would it work?
remiX #5
Posted 28 October 2012 - 06:16 AM
Correct, yeah. So it will make a hole 16x1x2 [LxWxH].

If you save the program as a file in the turtle folder in the mods folder for ComputerCraft, yes you will be able to run it with other turtles.
Mordlin #6
Posted 28 October 2012 - 06:24 AM
okay now If i wanted to hook this up to a transport pipe for deposit, Is there a command in tekkit, that checks the turtle's inventory space?

or do i just have it deploy the pipe and then pick it up after a few seconds?

if so would this work

turtle.select( 1 )
turtle.placeUp()
wait(5)
or something like that.

And also how do i get them to stop at bedrock?
ChunLing #7
Posted 28 October 2012 - 06:25 AM
No, it won't work. Now the new turtles will all follow exactly in the first turtle's path, instead of being stopped by the block the first turtle placed.

I believe that turtle.getItemCount() should work in 1.3. That's what I recall, and the minimum version requirements only started applying with 1.4 functions.
Mordlin #8
Posted 28 October 2012 - 06:29 AM
And what does turtle.getthemCount() do? does it could the inventory?
ChunLing #9
Posted 28 October 2012 - 06:42 AM
Check out the turtle API page. You should be able to use any function that doesn't have a minimum version requirement.
Mordlin #10
Posted 29 October 2012 - 02:40 AM
Okay so i am running into a problem when trying to make them come back up I have this

for i = 1,16 do turtle.dig() turtle.forward()
end
turtle.digDown()
turtle.down()
turtle.turnRight()
turtle.turnRight()
for i = 1,16 do turtle.dig() turtle.forward()
end
for i = 1,22 do turtle.up()
end
x,y,z=rednet.receive()
print(y)
if y ="go" then end
for i = 1,22 do turtle.down()
turttle.digDown()
turtledown()
for i = 1,16 do turtle.dig() turtle.forward()
end

and I get that I am missing a then somewhere.

Also here is the link to to full codehttp://pastebin.com/rUtp6AgQ
ChunLing #11
Posted 29 October 2012 - 03:54 AM
You can nest for (and other) loops, as long as you use different letters for the iteration (i) at each level. Also, when digging this sort of vertical pattern out, it makes sense to dig, digUp, and digDown so that you mine three blocks per move. It saves a good bit of fuel and time, as well as slowing down the actually movement of the turtle so you can shut them off if they "go wrong" during a test.

What you were missing was an end on one of the for loops. This probably just happened because you were using cut/paste instead of for loops to repeat things. It is one reason that I like to put short for loops (and other such things) all on one line if they will fit, you can treat the entire loop as a single line. Also, I'm a bit funny that way. I believe that you also intended the "if y ="go" then…end" structure to encompass the entire excavation part, as you had it it encompassed nothing, making it irrelevant whether or not y was equal to "go" because nothing different happened if it was than if it wasn't.

Here I've tried to reconstruct your intent as far as I can discern it:
repeat x,y,z=rednet.receive()
	print(y)
	if y ="go" then
		for i = 1,2, do turtle.digDown() turtledown() end
		for i = 1,7 do
			turtle.digDown()
			for j = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp() end
			for j = 1,3 do turtle.digDown() turtle.down() end
			turtle.turnRight()
			turtle.turnRight()
		end
		for i = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp()end
		turtle.digDown()
		for i = 1,26 do turtle.digUp() turtle.up() end
	end
until y = "no"
This is a loop that gets rednet messages until one says "no", at which point the loop terminates. If one of the messages is "go", then it dig/moves down two, and begins a trench, 26 deep and 17 long, by moving back and forth 8 times, or four "forth"s and four "back"s. It then ascends back up to where it started.

This version is much smaller and easier to check.

I should note that it is not actually necessary in this case to use different iterator names for each level of the loop, for iterators have scope within the loop and so there is no confusion on the program's part even if you use the same identifier for every level. But eventually you're going to want to do something with those iterator values during the loop, and then it is very good to be able to get them by having different identifiers for them.
Edited on 29 October 2012 - 02:57 AM
Mordlin #12
Posted 29 October 2012 - 05:33 AM

repeat x,y,z=rednet.receive()
	    print(y)
	    if y ="go" then
			    for i = 1,2, do turtle.digDown() turtledown() end
			    for i = 1,7 do
					    turtle.digDown()
					    for j = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp() end
					    for j = 1,3 do turtle.digDown() turtle.down() end
					    turtle.turnRight()
					    turtle.turnRight()
			    end
			    for i = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp()end
			    turtle.digDown()
			    for i = 1,26 do turtle.digUp() turtle.up() end
	    end
until y = "no"
Ahh makes since. You are a great help and I thank you.

When i go to test this however I get a call to nil error.
Heracles421 #13
Posted 29 October 2012 - 05:39 AM
Can you tell us the line number plz? I'm guessing that it has to do with the print(y) line, because it can't print something that's not there. You have the print(y) just after the x,y,z = rednet.recieve() and it hasn't got any messages yet, so the variable y is empty.


Try this and tell me if it works:
repeat x,y,z=rednet.receive()
        y ="waiting..."
	print(y)
	if y ="go" then
		for i = 1,2, do turtle.digDown() turtledown() end
		for i = 1,7 do
			turtle.digDown()
			for j = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp() end
			for j = 1,3 do turtle.digDown() turtle.down() end
			turtle.turnRight()
			turtle.turnRight()
		end
		for i = 1,16 do turtle.dig() turtle.forward() turtle.digDown() turtle.digUp()end
		turtle.digDown()
		for i = 1,26 do turtle.digUp() turtle.up() end
	end
until y = "no"
Mordlin #14
Posted 29 October 2012 - 06:00 AM
Fixed it. had a few extra commas and missing a period.

At the end of this code if i put

turtle.drop(1)
turtle.drop(2)
turtle.drop(3)
turtle.drop(4)
turtle.drop(5)
turtle.drop(6)
turtle.drop(7)
turtle.drop(8)
turtle.drop(9)
turtle.drop(10)
turtle.drop(11)
turtle.drop(12)
turtle.drop(13)
turtle.drop(14)
turtle.drop(15)
turtle.drop(16)
this will drop all the slots aand if a chest or pipe is there, put it in the storage
Heracles421 #15
Posted 29 October 2012 - 06:06 AM
Fixed it. had a few extra commas and missing a period.

At the end of this code if i put

turtle.drop(1)
turtle.drop(2)
turtle.drop(3)
turtle.drop(4)
turtle.drop(5)
turtle.drop(6)
turtle.drop(7)
turtle.drop(8)
turtle.drop(9)
turtle.drop(10)
turtle.drop(11)
turtle.drop(12)
turtle.drop(13)
turtle.drop(14)
turtle.drop(15)
turtle.drop(16)
this will drop all the slots aand if a chest or pipe is there, put it in the storage
There's a neater way of doing that:

s=1
repeat
    turtle.drop(s)
    s=s+1
until s > 16
Don't be afraid of maths :P/>/>
Mordlin #16
Posted 29 October 2012 - 06:40 AM
haha it isn't the math part, it is more of knowing how to code i feel. I don't know about assigning variables and when it is appropriate to do so.

and i can just add that bit before the end above until?
ChunLing #17
Posted 29 October 2012 - 11:19 AM
Ah, I messed up one of the turtle.down() calls and just had turtledown(). Sorry (but that exact "turtledown()" was taken from your code, so I think that I'm not the only one to blame for this).

You should use the iterative for loop for all cases of strict iteration, and the conditional loops for cases where the loop is expected to end before the maximum number of allowed iterations is reached. Just a style issue, mostly, though there are small internal differences between how the loops work.
Edited on 29 October 2012 - 10:23 AM
remiX #18
Posted 29 October 2012 - 06:07 PM

s=1
repeat
	turtle.drop(s)
	s=s+1
until s > 16
Don't be afraid of maths :P/>/>
for i = 1, 16
  turtle.drop(i)
end
Easier :P/>/>?
Heracles421 #19
Posted 29 October 2012 - 08:43 PM

s=1
repeat
	turtle.drop(s)
	s=s+1
until s > 16
Don't be afraid of maths :P/>/>
for i = 1, 16
  turtle.drop(i)
end
Easier :D/>/>?
True :P/>/>
Mordlin #20
Posted 08 November 2012 - 08:50 AM
Okay I think I got ahead of my self when I wanted them to drop their stuff. I need to first have something to add on to the loop making them dig forward up and down for 16 spaces, because of sand and gravel. I end up having to find and chase my turtles all over the place because of this lol. So i know i need to use turtle.detect() but how do I say if gravel do +1 to J
remiX #21
Posted 08 November 2012 - 08:52 AM
Make it do this before it moves forward:


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

That should work I think?
Mordlin #22
Posted 08 November 2012 - 09:25 AM
What about this makes it continue to do the mining pattern if gravel is detected?
Mordlin #23
Posted 08 November 2012 - 02:20 PM
or does it know to dig extra if it is gravel?
PixelToast #24
Posted 08 November 2012 - 02:55 PM
it waits a fraction of a second for gravel to fall after it digs if there is a block infront of it then it digs again
Mordlin #25
Posted 08 November 2012 - 07:21 PM
ahh okay

So if i just add that then all the square will be kept.

Thanks again guys
digpoe #26
Posted 09 November 2012 - 07:00 AM
Make it do this before it moves forward:


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

That should work I think?
It wouldn't work, as detect.forward() is not a function. Although, turtle.detect() is.
Also, a much better function to do would be:
repeat turtle.dig() sleep(.8) until not turtle.detect()
Mordlin #27
Posted 09 November 2012 - 02:03 PM
Ahh yes I was wondering if there was a wait function. This would work nicely, now to add this into the loops would look something like this

if turtle.detect =true do wait(8) end

and i just add that before the loops or, how would I make that a part of the loop
blacke00 #28
Posted 25 November 2012 - 04:50 AM
 s=1 repeat turtle.drop(s) s=s+1 until s > 16 
Don't be afraid of maths :D/>/>/>/>
for i = 1, 16 turtle.drop(i) end 
Easier :P/>/>/>/>?

Figured this might help, maybe? I adapted the above, (for myself) to this, ugly? probably. works, yep! =)

Now just need to work on refueling, gps functions, [strike]and getting my ore out of ender chest fast enough without Redpower (not on the server yet)[/strike] etc…

thoughts?


sleep(3) --just so I can watch everything happen after starting it.
turtle.select(16) --ender chest
turtle.placeUp()
for i = 1,15 do
  turtle.select(i)
  turtle.dropUp()
  end
turtle.select(16) --reselect slot 16 because I wanted ender chest to be replaced there
turtle.digUp()
PixelToast #29
Posted 25 November 2012 - 05:45 AM
looks good :3
Buho #30
Posted 29 January 2013 - 06:16 AM
When I do turtle.digUp() to collect my ender chest, I just get 8 obsidian in return. How are people using ender chests if the turtle uses a regular diamond pickaxe and not one with silk touch?