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

[Question] Looping redstone detector without error

Started by Carnivorious, 24 December 2012 - 10:01 AM
Carnivorious #1
Posted 24 December 2012 - 11:01 AM
So, basically I want to detect the redstone signal on my computer from my MFE Unit, to then show on my monitor the text "The MFE Unit is full." and when the signal is negative I would want the opposite. The signal comming from the MFE is good, and I can write a program to detect the signal and give a message accordingly, but if I want to loop it I always get the error code 178 which I assume equals a crash due to overlooping. I realised you can't use the While true do for this, so I want to use the os.pullEvent() but I have no idea how to do this. Without the loop I would use following code, then run the program on the monitor (doesn't have to be embedded into the code).


term.clear()
term.setCursorPos(1,1)
if redstone.getInput("right") == true then
print("The MFE Unit is full.")
else
print("The MFE Unit is not full.")
end

the term.clear() is a habit I picked up from Casper's interactive tutorial.
Thanks in advance!
Orwell #2
Posted 24 December 2012 - 11:42 AM
You'd do it like this:

while true do
  term.clear()
  term.setCursorPos(1,1)
  local e, side = os.pullEvent("redstone")
  if side == right and redstone.getInput(side) == true then
    print("The MFE Unit is full.")
  elseif side == right
    print("The MFE Unit is not full.")
  end
end
Carnivorious #3
Posted 24 December 2012 - 11:57 AM
When I launch this, I get the "178" error :/ Not sure what went wrong. I double checked it. Any other ideas?
Orwell #4
Posted 24 December 2012 - 12:10 PM
When I launch this, I get the "178" error :/ Not sure what went wrong. I double checked it. Any other ideas?
You'll have to post the full code then. It has got to be a combination of things.
Lyqyd #5
Posted 24 December 2012 - 02:29 PM
More like this, unless redstone events return the side now:

while true do
  os.pullEvent("redstone")
  term.clear()
  term.setCursorPos(1,1)
  if redstone.getInput("left") then --change left as necessary
    print("The MFE Unit is full.")
  else
    print("The MFE Unit is not full.")
  end
end
Carnivorious #6
Posted 24 December 2012 - 07:53 PM
When I launch this, I get the "178" error :/ Not sure what went wrong. I double checked it. Any other ideas?
You'll have to post the full code then. It has got to be a combination of things.

Actually, your program worked. Yet it only worked in singleplayer… any ideas why that is?
More like this, unless redstone events return the side now:

while true do
  os.pullEvent("redstone")
  term.clear()
  term.setCursorPos(1,1)
  if redstone.getInput("left") then --change left as necessary
	print("The MFE Unit is full.")
  else
	print("The MFE Unit is not full.")
  end
end
I'll try that out as soon as the server I play on is up :-)