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

[Question] Redstone wire and Computercraft in SMP

Started by Bandus, 25 March 2012 - 05:43 AM
Bandus #1
Posted 25 March 2012 - 07:43 AM
The question is simply: "Are there bugs with redstone wire and Computercraft in SMP?"

More specifically, I setup, what I thought, was a simple computer->redstone wiring->sticky piston to make a "dam" of sorts to stop/start water from flowing. If I go to the lua interface and manually input code such as redstone.setOutput("back", true) or redstone.setOutput("back", false) the redstone wiring powers on and off as expected. However, if I run my program (code provided below) when it is supposed to power on the redstone, the piston activates as intended, however the redstone never "turns on." As in, the redstone doesn't ever glow to indicate it is active, etc. After this happens, not even commands from the lua interpreter will affect the piston activating. I have to destroy it and place it again to get it to respond.

term.clear()
term.setCursorPos(1,1)
password = "water"
if redstone.getInput("back") == false then
print ("Deactivate Watering System? y/n")
x = io.read()
if x == "y" then
print("Please input authorization passcode:")
y = io.read()
  if y == password then
  print ("Watering System Shutting Down...")
  sleep(5)
  redstone.setOutput("back", true)
  os.shutdown()
  else
  print ("Incorrect Password.")
  sleep(3)
  os.shutdown()
  end
else
print("Canceled.")
sleep(3)
os.shutdown()
end
else
print ("Activate Watering System? y/n")
a = io.read()
  if a == "y" then
  print ("Please input authorization passcode:")
  b = io.read()
  if b == password then
  print ("Activating Watering System...")
  sleep (5)
  redstone.setOutput("back", false)
  os.shutdown()
  end
else
print("Cancelled.")
sleep(3)
os.shutdown()
end
end
Espen #2
Posted 25 March 2012 - 10:41 AM
Possible IF-structures:

if … end
if … else … end
if … elseif … else … end

You can use as many elseif's in a row as you like and one else as the last condition.
But the end only ever comes once, at the end of the whole if block. And it always has to be there after an if block ended!
Bandus #3
Posted 25 March 2012 - 09:28 PM
Possible IF-structures:

if … end
if … else … end
if … elseif … else … end

You can use as many elseif's in a row as you like and one else as the last condition.
But the end only ever comes once, at the end of the whole if block. And it always has to be there after an if block ended!

I've been re-evaluating my code with your advice in mind, but I'm just not seeing where I went astray. I feel like I closed every if statement properly with an end and didn't violate any of the guidelines you stated. Would you be willing to be slightly more specific?
Wolvan #4
Posted 25 March 2012 - 09:50 PM
Maybe i'ts because u used os.shutdown? Try to set the whole thing in a while loop and delete the os.shutdown()
Espen #5
Posted 25 March 2012 - 10:28 PM
I've been re-evaluating my code with your advice in mind, but I'm just not seeing where I went astray. I feel like I closed every if statement properly with an end and didn't violate any of the guidelines you stated. Would you be willing to be slightly more specific?

Sorry that was a case of mixing up lines, because of missing indentation. :o/>/>
Matching if's to their end's is one of the first things I do when someone reports problems, as that is often one of the culprits.
But since all of them seem fine I took another look at the code and agree with Wolvan.

That is, when you turn on the redstone then you immediately follow that with an os.shutdown().
The problem with the latter is that if a computer is off, it automatically turns off all redstone outputs.
So what your program does is to turn on the redstone and then quickly turn it off again.
And that happens so fast that your sticky piston essentially acts like a T-Flip-Tlop (at least in SSP).

To test if this is actually the problem, place a one second pause between turning on the redstone and the os.shutdown() and see if that gets rid at least of the non-responsive redstone problem. But even if it does you have to keep in mind that shutting down the computer always leaves the redstone outputs off. :o/>/>
Bandus #6
Posted 26 March 2012 - 12:52 AM
The os.shutdown() did appear to be the issue. Following both of your suggestions, I removed the os.shutdown() and it appears to function as expected now. I as unaware that shutting down the computer killed redstone output from the system, but haved noted that for the future. Thank you again for your assistance.