Catythcatmunchr Posted September 21, 2017 Posted September 21, 2017 For some reason break isn't exiting this while loop, when I input "exit" it just prints it and continues the loop instead leaving it. While true do Local input = term.read () Term.write (input) If input == "exit" then Break End End Quote
1 Molinko Posted September 22, 2017 Posted September 22, 2017 I believe term.read returns its input with a newline char (\n) appended to the end of its output. So, typing 'exit' would return 'exit\n'. One option is to use io.read if you don't need all of the options term.read offers. io.read will return the input without a newline. Or, you can strip the newline and compare as usual. local input = term.read() if input:sub(-2) == 'exit' then -- # I believe input:sub(-2) should strip the last two chars (\n) from the input variable... end Quote
0 Catythcatmunchr Posted September 22, 2017 Author Posted September 22, 2017 Thank you, input:sub(-2) didn't work but io.read() did work. I searched through the documentation and you are correct that term.read() adds a newline char. Quote
0 ben_mkiv Posted September 22, 2017 Posted September 22, 2017 '\n' is one character so it may be sub(-1) Quote
0 Molinko Posted September 22, 2017 Posted September 22, 2017 Thanks. It's always referenced as 'the' newline char Quote
For some reason break isn't exiting this while loop, when I input "exit" it just prints it and continues the loop instead leaving it.
While true do
Local input = term.read ()
Term.write (input)
If input == "exit" then
Break
End
End