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

Laying fence

Started by TheGreekMan2, 01 June 2014 - 12:18 AM
TheGreekMan2 #1
Posted 01 June 2014 - 02:18 AM
I want to make a CC program that can make a specified size rectangle. The code doesn't come up with any errors, but when i run the program the turtle doesn't do what it's supposed too. Thanks for any help





local s = 1
turtle.select(1)

local function placeFence()
turtle.digDown()
turtle.placeDown()
while not turtle.forward() do
turtle.dig()
end
turtle.forward()
end

if turtle.getItemCount(s) == 0 then
s = s+1
turtle.select(s)
end

local function layingFence()
term.clear()
term.setCursorPos(1,1)
print("How long do you want the quarry?")
x = tonumber(read())
print("How wide do you want the quarry?")
y = tonumber(read())
print("Laying fence " .. x .. " by ".. y)
end

layingFence()
for i=1, x do
placeFence()
end
turtle.turnLeft()

for i=1, y do
placeFence()
end
turtle.turnLeft()

for i = 1, x do
placeFence()
end
turtle.turnLeft()

for i=1, y do
placeFence()
end
turtle.up()
sk8mn #2
Posted 01 June 2014 - 02:54 AM
Sorry I posted but misread half of the code…..
Edited on 01 June 2014 - 12:56 AM
Bomb Bloke #3
Posted 01 June 2014 - 03:54 AM
Bearing in mind that calling "turtle.forward()" 1) attempts to go forward and 2) returns true/false depending on whether it succeeded, this code:

while not turtle.forward() do
turtle.dig()
end
turtle.forward()

… says "until you can move forward once, dig in front of you. Once you've gone forward once, try to go forward a second time".

Ditch the second "turtle.forward()".
TheGreekMan2 #4
Posted 01 June 2014 - 04:00 AM
thank you sir :)/>