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

mining turtle help please

Started by wowquevvexx, 05 May 2012 - 05:41 PM
wowquevvexx #1
Posted 05 May 2012 - 07:41 PM
ok this is what imi trying to do im trying to set it up so i tell it to excavate 30 so it does then ones its full it comes back to starting place well then i want it to send out a redstone current untill its empty so i can use buildcraft to empty it then have it be told to start excavate 30 again please anyone and im really new at this so if you have a better way like without buildcraft or somthing that will do this for me please also please go step by step im really new at it
Lyqyd #2
Posted 06 May 2012 - 06:26 AM
Why not just put an obsidian pipe someplace and have it turtle.drop() everything in there, one slot at a time? That's what I have my mining turtles do.

But it would be something like:


redstone.setOutput("back", true)
while turtle.getItemCount(9) > 0 do
sleep(5)
end
redstone.setOutput("back", false)

Though, if you're using something higher than just a redstone engine, you might want to include some cooldown time in there.
wowquevvexx #3
Posted 07 May 2012 - 02:01 AM
im confused so waht your saying is have it put out a redstone current in back then tell it so when it has a redstone current at back so ones it full to drops its items to say to the left so a obsidain pipe can pick up then have it do excavate again if so or not please please please tell me exaclty command by command how to set it on a loop so ones its full it drops items then goes excavating again im really new at it
wowquevvexx #4
Posted 07 May 2012 - 02:06 AM
the post aboves directed to you
wowquevvexx #5
Posted 07 May 2012 - 02:26 AM
ok i just thought is there a way to do this if event full redstone back then if event empty excavate 30
if so please step by step by step im still trying to learn how to event get to the code thing
dirtywastegash #6
Posted 08 May 2012 - 11:33 AM
what Lyqyd was trying to say,
is it would be much easier to get the turtle to drop the items into an obsidian pipe in a set place than to get a pipe to suck the items from the turtle

as all you have to do is tell the turtle

turtle.drop()
and it will empty itself onto the floor.
Lyqyd #7
Posted 08 May 2012 - 06:27 PM
Well, I'm not going to write it for you. It's a fairly simple matter to check how full a turtle is (look up the turtle API) and it is also relatively simple to have a turtle return to a starting point. The code snippet I posted above would be an example of having a turtle turn on an engine via a redstone signal in order to have items pumped out of it. That code snippet assumes that all slots have something in them though.

You may wish to look up some lua tutorials if you're still unsure how to begin.
PixelToast #8
Posted 11 May 2012 - 05:05 AM
function areSlotsLeft()
for n=1,9 do
if turtle.getItemCount(n) == 0 then
return true
end
return false
end
Lyqyd #9
Posted 11 May 2012 - 05:42 AM
That would return true if the first slot is empty and false if it isn't.

Try it!
Luanub #10
Posted 11 May 2012 - 06:42 AM
Its fairly easy and probably more accurate to get a pipe to remove the objects from the turtle vs using an obsidian pipe. I have a spot setup on my map for my turtle to empty its inventory and refill its sappling supply. I put one pipe underneath to empty and one coming in from the side to refil slot one with sapplings.

You have a chance of the obsidian pipe not always picking up what the turtle drops meaning you will have to either go pick it up yourself, or lose the items.

I can share my code that I use to do this with if you need.
PixelToast #11
Posted 11 May 2012 - 07:29 AM
That would return true if the first slot is empty and false if it isn't.

Try it!
nope, ripped the code straight from the excavate program :)/>/> i think it works fine in game
would you like me to comment the code?
Luanub #12
Posted 11 May 2012 - 09:50 AM
Here is the way I do it. I do not empty slot #9, just change the table to the slots that you want to empty. You could also remove the table and change to the for loop to one like what is in the post above.

function unload()
slots = {1, 2, 3, 4, 5, 6, 7, 8 }
for var, x in pairs(slots) do
    if turtle.getItemCount( x ) ~= 0 then
        while turtle.getItemCount ( x ) ~= 0 do
        rs.setOutput("bottom", true )
        sleep (0.25)
        end
        rs.setOutput("bottom", false )
    end
end
end
Lyqyd #13
Posted 12 May 2012 - 05:12 PM
That would return true if the first slot is empty and false if it isn't.

Try it!
nope, ripped the code straight from the excavate program :P/>/> i think it works fine in game
would you like me to comment the code?

No, you didn't. This is directly from excavate:


for n=1,9 do
	if turtle.getItemCount(n) == 0 then
   	 return true
	end
end
	
print( "No empty slots left." )
return false

This is what you wrote:


function areSlotsLeft()
	for n=1,9 do
		if turtle.getItemCount(n) == 0 then
			return true
		end
		return false
	end

I even indented it so you may be able to see the flow better. Notice how you're missing an end. You obviously didn't try it in game before claiming that it works properly. Follow it through.

The first one will loop through the slots until the first empty slot, where it will return true. If it loops through all nine slots without finding any empties, it will then move onward to the return false. Because you're missing an end, yours will check if the first slot is empty. If it is, it will return true. If it isn't, it'll pass through the if and return false before it would reach the end of the loop body. Go actually try it with a turtle with a non-empty first slot. It'll return false.


Its fairly easy and probably more accurate to get a pipe to remove the objects from the turtle vs using an obsidian pipe. I have a spot setup on my map for my turtle to empty its inventory and refill its sappling supply. I put one pipe underneath to empty and one coming in from the side to refil slot one with sapplings.

You have a chance of the obsidian pipe not always picking up what the turtle drops meaning you will have to either go pick it up yourself, or lose the items.

I can share my code that I use to do this with if you need.

I've found that if you have the turtle drop down into a 1x1 shaft with the obsidian pipe at least one block below it, it will not fail to pick up all the items. The other pipe would have to then come in from behind or a side (in front could result in items sticking at the top, potentially)
PixelToast #14
Posted 13 May 2012 - 11:52 PM
i copied it from npp wrong, accidentaly removing the end, sorry