Only have one small problem: once the robot has placed one stack, of blocks, it keeps moving forwards without placing anymore blocks as the wrong slot number is selected, so I made this code:
local level = turtle.getItemCount()
local slotnum = turtle.getSelectedSlot()
while true do
if level == 0 then
if slotnum <= 18 then
slotnum = slotnum+1
sleep(0.1)
turtle.select(slotnum)
end
end
end
I thought it would do
1. every second start the program – that works (while true do)
2. if local level == 0 (i.e. no items in selected slot and the number of items is found using turtle.getItemCount)
then: if the slotnum is less than 18 - as there is 18 slots - go to the next slot. this would repeat this until it found a slot that had items (unless it didn't have any items)
4. when it found a slot with items it would select that slot and stop "searching" (allowing me to place blocks)
5. When that slot runs out it would start again until it found another slot.
What it actually does:
selects slots from 1 to 18 one after the other but doesn't check if these slots contains items then exits the code saying there isn't 17 slots.
The full code can be found here:
Turtle code
rednet.open("right")If you get rid from here
local level = turtle.getItemCount()
local slotnum = turtle.getSelectedSlot()
while true do
if level == 0 then
if slotnum >= 18 then
slotnum = slotnum+1
sleep(0.1)
turtle.select(slotnum)
end
end
end
To here it works fine - but doesn't change slot number
while true do
local sender, message, protocol = rednet.receive()
if message == "left" then
turtle.turnLeft()
end
if message == "right" then
turtle.turnRight()
end
if message == "forward" then
turtle.forward()
end
if message == "back" then
turtle.back()
end
if message == "placedown" then
turtle.placeDown()
end
if message == "placeup" then
turtle.placeUp()
end
if message == "up" then
turtle.up()
end
if message == "down" then
turtle.down()
end
if message == "break" then
turtle.dig()
end
end
Computer code
rednet.open("back")local disf = 0
local disb = 0
local disr = 0
local disl = 0
local disv = 0
while true do
term.clear()
term.setCursorPos(1,1)
print("Height "..disv)
– print("Right "..disr)
– print("Left "..disl)
print("Forwards "..disf)
print("Back "..disb)
local event, character = os.pullEvent("char")
if character == "p" and "o" then
disf = 0
disb = 0
disr = 0
disl = 0
disv = 0
end
if disr == -4 then
disr = 0
end
if disl == -4 then
disl = 0
end
if character == "w" then
rednet.broadcast("forward")
if disb >= 1 then
disb = disb-1
else
disb = 0
disf = disf+1
end
end
if character == "a" then
rednet.broadcast("left")
if disr >= 1 then
disr = disr-1
else
disl = disl+1
disr = 0
end
end
if character == "s" then
rednet.broadcast("back")
if disf >= 1 then
disf = disf-1
else
disb = disb+1
disf = 0
end
end
if character == "d" then
rednet.broadcast("right")
if disl >= 1 then
disr = disr-1
else
disl = disl+1
disr = 0
end
end
if character == "g" then
rednet.broadcast("down")
if disv >= 0 then
disv = disv-1
end
end
if character == "h" then
rednet.broadcast("up")
if disv >= 0 then
disv = disv+1
end
end
if character == "e" then
rednet.broadcast("placedown")
end
if character == "q" then
rednet.broadcast("placeup")
end
if character == "f" then
rednet.broadcast("break")
end
end