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

Turtle Made Sand Wall

Started by Debugger, 05 March 2013 - 04:56 AM
Debugger #1
Posted 05 March 2013 - 05:56 AM
Hello all. I need to make a long wall in the ocean out of sand and thought programming a turtle would be a nice intro to turtle scripting.
I'm used to C# { open and closed } syntax, so I'm almost certain my issue is syntax based.

The idea is simple. Check slot one for sand, if no sand, move to a slot that has sand. Keep dropping sand below until a block is detected below, then move forward one block and repeat the process until i = 10.

It looks like it cycles through the inventory correctly, but fails on the while == false.




s = 2 --slot number

turtle.select(1)
turtle.refuel()

for i=1,10 do

if turtle.detectDown() then 
turtle.forward()
end

while turtle.detect.Down() == false do

  if turtle.getItemCount(s) < 1 then s = s + 1
   turtle.select(s)
   turtle.placeDown()
   end --end if
end -- end while do loop

end --end for loop

Lyqyd #2
Posted 05 March 2013 - 07:15 AM
Split into new topic.

turtle.detect.Down should be turtle.detectDown and you may want a short sleep at the end of the while loop to allow sand to fall before the next detection.
Debugger #3
Posted 05 March 2013 - 08:44 AM
Split into new topic.

turtle.detect.Down should be turtle.detectDown and you may want a short sleep at the end of the while loop to allow sand to fall before the next detection.

Guess I know why it failed on the while turtle.detect.Down == false line! Thanks Lua Liquidator!
Engineer #4
Posted 05 March 2013 - 09:43 AM
You alse should sleep(0.4) before you check below, because then the sand is dropped when it is dropped. :)/>
Note: Just like Lyqyd said, but I defined it a little bit more :P/>
immibis #5
Posted 05 March 2013 - 11:33 AM
With fixed indentation:

while turtle.detectDown() == false do
  if turtle.getItemCount(s) < 1 then
    s = s + 1
    turtle.select(s)
    turtle.placeDown()
  end --end if
end -- end while do loop

Notice anything? It'll only place the sand if the slot was empty.