31 posts
Posted 26 November 2012 - 02:17 PM
I'm new to lua but I am trying to make a strip mining Turtle, I reference this code,
local function dropCobble()
turtle.select(2)
if turtle.compare(1) and turtle.getItemCount(2) > 63 then
turtle.drop()
end
end
This is to check to see if i'm full on cobblestone and if I am and the block infront of me is regular stone it drops the stack and picks up the stone,
However the cobblestone won't stack on each other! it starts a new stack? Dirt and Gravel do fine. what's wrong with my cobblestone?
For the working Dirt one it's the same thing but it's
local function dropDirt()
turtle.select(4)
if turtle.compare(4) and turtle.getItemCount(4) > 63 then
turtle.drop()
end
end
anyone have any ideas?
8543 posts
Posted 26 November 2012 - 02:19 PM
For one, you can't compare cobble and smooth stone. They're different. For another, the turtle will place dug items in whatever slot you have selected, so make sure you have the correct slot selected when digging.
31 posts
Posted 26 November 2012 - 02:21 PM
For one, you can't compare cobble and smooth stone. They're different. For another, the turtle will place dug items in whatever slot you have selected, so make sure you have the correct slot selected when digging.
Thank you for the reply, I have smooth stone in Slot 1 and Cobblestone in Slot 2 if that clears that up, it's checking to see if the block is indeed Smooth Stone and if it is and if I have a full stack of Cobblestone it will drop the cobblestone and pick up the Stone but it won't let cobblestone stack in the second slot,
8543 posts
Posted 26 November 2012 - 02:25 PM
Where does the selection end up when you dig the block?
31 posts
Posted 26 November 2012 - 02:27 PM
Thank you again for responding,
it ends up in slot 4 I'd assume (I don't know why it would) when it checks slot 4 but goes to 5 because it isn't dirt, I dunno how to unselect a slot. I'm new to scripting and this mod but,
My code is as follows, if you could tell me what I could do different to unselect slots i'd be grateful.
local function digIfDetect()
if turtle.detect() then turtle.dig() end
end
local function digDownIfDetect()
if turtle.detectDown() then turtle.digDown() end
end
local function dropCobble()
turtle.select(2)
if turtle.compare(1) and turtle.getItemCount(2) > 63 then
turtle.drop()
end
end
local function dropGravel()
turtle.select(3)
if turtle.compare(3) and turtle.getItemCount(3) > 63 then
turtle.drop()
end
end
local function dropDirt()
turtle.select(4)
if turtle.compare(4) and turtle.getItemCount(4) > 63 then
turtle.drop()
end
end
local function dropDownCobble()
turtle.select(2)
if turtle.compareDown(1) and turtle.getItemCount(2) > 63 then
turtle.drop()
end
end
local function dropDownGravel()
turtle.select(3)
if turtle.compareDown(3) and turtle.getItemCount(3) > 63 then
turtle.drop()
end
end
local function dropDownDirt()
turtle.select(4)
if turtle.compareDown(4) and turtle.getItemCount(4) > 63 then
turtle.drop()
end
end
for i=1, 50 do
for i=1, 3 do
if turtle.getFuelLevel() < 55 then
turtle.refuel(3)
end
for i=1, 50 do
dropCobble()
dropGravel()
dropDirt()
digIfDetect()
turtle.forward()
end
turtle.turnRight()
turtle.turnRight()
dropDownCobble()
dropDownGravel()
dropDownDirt()
digDownIfDetect()
turtle.down()
end
for i=1, 4 do
turtle.up()
end
for i=1, 50 do
turtle.forward()
end
for i=1, 3 do
turtle.turnRight()
end
dropCobble()
dropGravel()
dropDirt()
digIfDetect()
turtle.forward()
for i=1, 3 do
turtle.turnRight()
end
end
8543 posts
Posted 26 November 2012 - 02:37 PM
Try adding a turtle.select(1) in digIfDetect before it digs.
31 posts
Posted 26 November 2012 - 02:46 PM
Try adding a turtle.select(1) in digIfDetect before it digs.
You are awesome! Thank you so much it works great!
31 posts
Posted 26 November 2012 - 03:35 PM
Actually, I have a new problem! it won't drop the stack even though it's full! I have it so it checks it and if it's full it will select it, then compare, and then drop but for whatever reason it refuses to drop.
8543 posts
Posted 26 November 2012 - 03:37 PM
turtle.compare doesn't take an argument. So the cobble ones won't work, since you're trying to compare with another slot that isn't the selected one. Try having it select the slot to compare to, then doing the comparison, then selecting and dropping the relevant stack if it needs to be dropped.
31 posts
Posted 26 November 2012 - 03:53 PM
turtle.compare doesn't take an argument. So the cobble ones won't work, since you're trying to compare with another slot that isn't the selected one. Try having it select the slot to compare to, then doing the comparison, then selecting and dropping the relevant stack if it needs to be dropped.
Tried your suggestion thank you so much for everything! it's working perfectly now!