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

Wall Building.

Started by mrpoopy345, 04 December 2013 - 04:43 PM
mrpoopy345 #1
Posted 04 December 2013 - 05:43 PM
Hello! I have created a wall building program, and I need help. So, the program works fine, except for big walls, I want it to detect when the slot it is on is empty and switch to the next slot. I wrote some code for it, but it is not working. No errors, it just does not switch. Any help?
Current code:

print("How long?")
local long = read()
print("How tall?")
local tall = read()
function wall()
 for i = 1, tall do
  turtle.up()
 for i = 1, long do
  turtle.placeDown()
  turtle.forward()
 end
 for i = 1, long do
  turtle.back()
 end 
end
end
a = 1
--Program
if turtle.getItemCount(a) == "0" then
 a = a + 1
 turtle.select(a)
 wall()
else
 wall()
end
mrpoopy345 #2
Posted 04 December 2013 - 06:42 PM
Please? Anyone?
Bomb Bloke #3
Posted 04 December 2013 - 06:54 PM
You're checking to see if your block slot is empty, then trying to build the entire wall without checking again.

Instead, you want to rig things so that it performs that check each time it goes to place a block.

Quick untested re-write:

Spoiler
local long,tall
local curslot = 1
turtle.select(curslot)

while not long do  -- Loop while "long" is nil.
  print("How long?")
  long = tonumber(read())  -- This returns a proper numeric variable, or nil if a number wasn't entered.
end

while not tall do
  print("How tall?")
  tall = tonumber(read())
end

local function wall()
  for i = 1, tall do
    turtle.up()
    for j = 1, long do
      while turtle.getItemCount(curslot) == 0 do  -- Loop until we find a slot with items.
        curslot = curslot + 1
        turtle.select(curslot)
      end    

      turtle.placeDown()
      turtle.forward()
    end
    for j = 1, long do
      turtle.back()
    end 
  end
end

wall()