Posted 11 November 2012 - 09:54 AM
Hello! I am completely new to ComputerCraft and LUA (just started messing with LUA today!)
I am running the most current Tekkit server and client, which means I am using CC 1.33.
My bridgebot moves forward and mines or lays blocks as needed to create a tunnel/catwalk through the upper blocks of the nether.
My bridge-building bot doesn't seem to recognize when he is out of materials. I tried to fix that by cobbling some found code together here and other places, but I am just too new to the language to know what I am doing wrong.
When I run the code with the "checkslot" inventory detector, the turtle does nothing. Without it, and with a simple "repeat X times" appended to the bottom, the rest of the code works as intended (accept it simply keeps going until X times regardless of whether is has the materials to use…
I suspect I am simply not properly calling my functions, or doing it in a backwards way. I simply want the turtle to:
1. check his selected slot before placing a brick.
2. if that slot has less than 4 items remaining in it, then switch to the next slot.
3. If, after depleting what is in slots 1-5 - and he has selected slot 6 - AND it has less than 4 items, stop the program.
Can anyone lend a little instruction?
Thank you, guys. And it is a fantastic mod, by the way!
I am running the most current Tekkit server and client, which means I am using CC 1.33.
My bridgebot moves forward and mines or lays blocks as needed to create a tunnel/catwalk through the upper blocks of the nether.
My bridge-building bot doesn't seem to recognize when he is out of materials. I tried to fix that by cobbling some found code together here and other places, but I am just too new to the language to know what I am doing wrong.
When I run the code with the "checkslot" inventory detector, the turtle does nothing. Without it, and with a simple "repeat X times" appended to the bottom, the rest of the code works as intended (accept it simply keeps going until X times regardless of whether is has the materials to use…
local i = 1
local
slotNum = 1
function checkslot()
if turtle.getItemCount(slotNum) < 4 then
if slotNum == 6 then
return false
end
for i = slotNum+1, 6 do
if turtle.getItemCount > 4 then
slotNum = i
turtle.select(slotNum)
return true
end
end
end
end
function bridgechunk()
turtle.turnLeft()
if not turtle.detect() then
checkslot()
turtle.place()
end
turtle.turnLeft()
turtle.turnLeft()
if not turtle.detect() then
checkslot()
turtle.place()
end
turtle.turnLeft()
end
function spinmine()
if not turtle.forward() then
turtle.dig()
turtle.forward()
turtle.digUp()
bridgechunk()
end
if not turtle.detectDown() then
turtle.placeDown()
bridgechunk()
end
end
while checkslot()==true do
spinmine()
print ("Let's Roll!")
end
I suspect I am simply not properly calling my functions, or doing it in a backwards way. I simply want the turtle to:
1. check his selected slot before placing a brick.
2. if that slot has less than 4 items remaining in it, then switch to the next slot.
3. If, after depleting what is in slots 1-5 - and he has selected slot 6 - AND it has less than 4 items, stop the program.
Can anyone lend a little instruction?
Thank you, guys. And it is a fantastic mod, by the way!