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

redstone signal loop

Started by xInDiGo, 03 May 2013 - 12:12 PM
xInDiGo #1
Posted 03 May 2013 - 02:12 PM
i'm trying to make a startup script that will check for a redstone signal. if the redstone signal is true it will do some functions, if not it will sit and wait for the redstone signal. this is what i've got so far but its not working :(/>


while redstone.getInput("right") == true do
	    place()
	    drop()
	    else
	    sleep(1)
end

the error i get is "bios:383: [string "startup"]:27: 'end' expected (to close 'while' at line 24)"

i've added extra ends around line 27 but its not helping. thanks for the support!
Smiley43210 #2
Posted 03 May 2013 - 02:18 PM
While loops don't take "else" conditions. If statements do. In this case, consider trying
while true do
  if redstone.getInput("right") then -- We don't need to say == true because if statements just check if the condition evaluates to true'
	place()
	drop()
  else
	sleep(1)
  end
end
Also, remember that to break out of any loop (while, for, repeat), you must use "break" (without the quotation marks).
xInDiGo #3
Posted 03 May 2013 - 03:25 PM
thanks very much! :)/>