8 posts
Posted 28 August 2013 - 06:03 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. I know it's bad to call a function in a function but I don't know what else to do!
871 posts
Posted 28 August 2013 - 06:17 PM
Put it in a while loop to make it repeat, instead of calling itself.
Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.
redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
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 recognised."
end
end
end
8 posts
Posted 28 August 2013 - 06:34 PM
Put it in a while loop to make it repeat, instead of calling itself.
Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.
redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
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 recognised."
end
end
end
I typed that in exactly and when i try to run it it gives me a 204 error.
8 posts
Posted 28 August 2013 - 06:43 PM
Put it in a while loop to make it repeat, instead of calling itself.
Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.
redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
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 recognised."
end
end
end
I typed that in exactly and when i try to run it it gives me a 204 error.
Never mind I figured it out
32 posts
Location
UK
Posted 28 August 2013 - 06:44 PM
Put it in a while loop to make it repeat, instead of calling itself.
Also, use elseif, not else. As written it would be showing "command not recognized" twice if you weren't calling A again the first time, you should only have one final "else" at the end.
redstone.setOutput("right", true)
print "Type 'open' or 'close' to Open or close the airlock."
function A()
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 recognised."
end
end
end
I typed that in exactly and when i try to run it it gives me a 204 error.
works fine for me, make sure you call the function with A() at the end
871 posts
Posted 28 August 2013 - 07:13 PM
FYI, the number before the : in Lua error messages is the line number where the error occurs, not a code identifying the type of error.
83 posts
Location
Behind you
Posted 29 August 2013 - 01:34 AM
It looks like you aren't calling the function after you make it.
Use A() after you define it to actually call the function
To make Last1Here's comment more distinguished, I left out the giant quote, but basically I'm repeating what they said.