Jump to content




whats wrong with my program?


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

#1 ironwiccan

  • Members
  • 78 posts

Posted 17 June 2013 - 11:49 PM

I'm trying to make a turtle that patrols a hallway and turns around at the ends, but it stops at the wall...help?

 turtle.refuel(1)
sleep(1)
 while true do
 turtle.detect()
 end
 if false then
  turtle.forward()
  turtle.attack()
 else
  turtle.turnLeft()
  turtle.turnLeft()
 end


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 18 June 2013 - 12:08 AM

Um, no. That program literally doesn't do anything. It would refuel, sleep for one second, and then sit there using turtle.detect() forever. Please give us your entire actual code so that we can help fix it.

#3 ironwiccan

  • Members
  • 78 posts

Posted 18 June 2013 - 01:09 AM

Sorry. I guess I had an older version saved on my phone. Ill post the rest asap

#4 IntrovertedSiko

  • Members
  • 3 posts

Posted 18 June 2013 - 04:04 PM

I'm just starting out but.... isn't the first "end" closing the "while" loop? :/ so pretty much it'll just keep detecting...

Try this:
function ______
turtle.refuel(1)
sleep(1)
while true do
if turtle.detect() then --If it detects then...

Do
  Stuff
              
   end
end

Also, this will refuel and sleep once, then jump into the circle of whatever. So maybe you don't want a while true loop. Try a repeat or for loop?
:)

P.S you can put "if not...." if you want to reverse what you want to do

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 June 2013 - 07:39 PM

I'm thinking this is what you want:
turtle.refuel(1)
while true do
  if not turtle.detect() then
    turtle.forward()
    turtle.attack()
  else
    turtle.turnLeft()
    turtle.turnLeft()
  end
end

In English readable form:
Refuel the turtle.
Do the following while true is true:
  Do the following if the turtle does not see a block in front:
    Go forward.
    Attack.
  Otherwise:
    Turn around.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users