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

Why Isnt My Code Working?

Started by Th3RadMan, 23 September 2013 - 09:10 PM
Th3RadMan #1
Posted 23 September 2013 - 11:10 PM
I made this but it isnt doing anything

(its not completely done)


x = rs.getBundledInput("left", colors.magenta)
while true do
  if x == true then
    print("sleeping")
    sleep(10)
    elseif x == false then
	  term.clear()
	  setCursorPos(1,1)
	  print("checking")
	  sleep(10)
	  if x == false then
	    term.clear()
	    setCursotPos(1,1)
	    print("moving")
	    rs.setBundledOutput("left",colors.red)
	    rs.setBundledOutput("right",colors.red)
	    sleep(.5)
	    rs.setBundledOutput("left", 0)
	    rs.setBundledOutput("right", 0)
	  end
    end
  end

what should happen is if gets a rs signal it will say its sleeping and wont do anything (liquid in tank) and if there isnt any it will say "checking" and test again in 10 seconds. if there is still no liquid it will send a rs.bundledoutput, say (moving) wait, then stop the signal

but some reson it wont get started… it doesnt say anything and doesnt send the rs.bundled cable

should i change print to term.write? also whats the difference?
and i know i'll get this, ill put a term.clear() and a setCursorPos

what will make this work?
jay5476 #2
Posted 24 September 2013 - 12:40 AM
your checking it once and then doing the loop for that result every time move x = rs.getBundledInput into the top of your while loop so that it will check again
UltraNoobian #3
Posted 24 September 2013 - 05:41 AM
Okay first off, like jay5476 said, You need to move the BundledInput check inside the loop or else it will just be stuck on whatever the input happened to be when you run this program.

Literally move Line 1 to inbetween Line 2 and 3
x = rs.getBundledInput("left", colors.magenta) <----
while true do
  if x == true then
	print("sleeping")
	sleep(10)
to
while true do
  x = rs.getBundledInput("left", colors.magenta) <---
  if x == true then
	print("sleeping")
	sleep(10)

====
should i change print to term.write? also whats the difference?
Write() will write to the line where the cursor is and will leave the cursor position where it ends.
Print() will write to the line where the cursor is but will move the cursor to the start of the next line.
Th3RadMan #4
Posted 24 September 2013 - 09:47 AM
i did that and it says lava :2: Too long without yielding
LBPHacker #5
Posted 24 September 2013 - 10:04 AM
  • Check the magenta wire in the loop, not before the loop. That way it'll actually be updated. (EDIT: Yeah, I know, this one's already been mentioned…)
  • Check it with rs.testBundledInput, not with rs.getBundledInput.
i did that and it says lava :2: Too long without yielding
Coincidence. Lua throws the TLWY error whenever it feels like "hell, this coroutine has been running for too long". The line number tells you nothing important in this case.

And anyways, a TLWY wouldn't have been possible if you hadn't removed one of the sleeps.

BTW this:
if x == true then
    ...
elseif x == false then
    ...
end
is the same as
if x then
    ...
else
    ...
end