Jump to content




Turtle Made Sand Wall


  • You cannot reply to this topic
4 replies to this topic

#1 Debugger

  • Members
  • 16 posts

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



#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#3 Debugger

  • Members
  • 16 posts

Posted 05 March 2013 - 08:44 AM

View PostLyqyd, on 05 March 2013 - 07:15 AM, said:

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!

#4 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

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

#5 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users