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

piston airlock

Started by qwerty6543, 28 August 2013 - 03:36 PM
qwerty6543 #1
Posted 28 August 2013 - 05:36 PM
I am trying to make a piston airlock and I was wondering how to make it so at a certant point it will go back to a place in the command, Here is my script:


redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
print ""
write ">"
input = read()
if input == "open" then
   print "Opening..."
   redstone.setOutput("right", false)
   A()
else
   print "Command not recognised."
   A()
end
if input == "close" then
   print "Closing..."
   redstone.setOutput("right", true)
   A()
else
   print "Command not recognised."
   A()
end
end


When I try to run it it just says the first line and then goes to the normal console. Help?
jay5476 #2
Posted 28 August 2013 - 05:44 PM
@qwerty you never call A() and also its bad to call A() within A() it will lead to a stack error use a while loop
qwerty6543 #3
Posted 28 August 2013 - 05:47 PM
@qwerty you never call A() and also its bad to call A() within A() it will lead to a stack error use a while loop

Do you think you could suggest to me how to make it better so it works?
GopherAtl #4
Posted 28 August 2013 - 05:57 PM
what on earth did you post this question in this old, unrelated thread for?
Luanub #5
Posted 29 August 2013 - 03:28 AM
I am trying to make a piston airlock and I was wondering how to make it so at a certant point it will go back to a place in the command, Here is my script:


redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
print ""
write ">"
input = read()
if input == "open" then
   print "Opening..."
   redstone.setOutput("right", false)
   A()
else
   print "Command not recognised."
   A()
end
if input == "close" then
   print "Closing..."
   redstone.setOutput("right", true)
   A()
else
   print "Command not recognised."
   A()
end
end


When I try to run it it just says the first line and then goes to the normal console. Help?

You really should have posted a new topic instead of replying to an old one like this.

But to answer your question you dont even need to have a function. Just put certain parts of the code in a loop. You also do not need two if statements, you can do what your wanting using an elseif in the statement.


redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."

while true do
print ""
write ">"
input = read()
if input == "open" then
   print "Opening..."
   redstone.setOutput("right", false)
elseif input == "close" then
   print "Closing..."
   redstone.setOutput("right", true)
else
   print "Command not recognized."
end
end