Jump to content




i need help with while statements


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

#1 dcleondc

  • New Members
  • 70 posts

Posted 01 August 2012 - 04:13 AM

i need to compare a block its above with a block it has selected and if its true i need it to run one code and if its false i need it to run a different code.
here is the code i have that doesn't work.
function done()
    turtle.select(16)
    while turtle.compareDown() do
	    farm()
    else
	    skip()
    end
end
the function is part of a farming program im making.

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 01 August 2012 - 04:16 AM

Hey man it's been awhile. while statements do not contain else functions, you will need to add in if into it. Try doing something like

function done()
    turtle.select(16)
    while turtle.compareDown() do
    if turtle.compareDown() then
            farm()
    else
            skip()
    end
    end
end


#3 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 01 August 2012 - 05:33 AM

You are aware of the fact that the else statement will never get called? I rather think he should replace the while with an if in his first code.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users