Posted 09 March 2013 - 10:58 AM
So I was making a disk that opens a door to the right and ejects itself. I want the ejection to be optional. How do I do this? Also, I want the user to input the "Yes" "No" for eject.
print( "Would you like to eject the disk? (Yes/No)" )
local opt
local cx, cy = term.getCursorPos()
repeat term.setCursorPos( cx, cy ) term.clearLine() opt = read():lower() until opt == "yes" or opt == "no"
if opt == "yes" then
disk.eject( 'right' )
else
print( 'okay :o/>' )
end
--first lets open the file we want to read > opening in reading mode, "r"
local file = fs.open("/disk/mydoorside", "r")
-- lets read the file:
local fileReader = file.readAll()
--And what you must never forget, close the file.
file.close()
-- Determine wich side to set the redstone output
if fileReader == "right" then
redstone.setOutput("right", true)
-- etc.
elseif fileReader == "left" then
redstone.setOutput("left", true)
-- etc
else
print("The file is invalid to me")
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Would you like to eject the disk? (y/n)")
evt, p1 = os.pullEvent()
if evt == "char" and
p1 == "y" then
disk.eject("right")
print("Disk ejected!")
sleep(2)
elseif p1 == "n" then
print("Disk was not ejected!")
sleep(2)
end
end