Using io.read() without halting the game
Posted: Wed Dec 12, 2018 5:09 pm
Hello,
So I would like to use io.read() in my game, as it allows the user to input commands using the terminal approach. This is a great feature for my server edition of my game. However, I do not want to bring the entire game to a halt. I tried slapping io.read() on its own thread, and was planning on having a separate thread for printing console output.
However, my code is doing this strange thing where if I have 'io.read()' it will halt executing code before it, then I have to tap the 'enter' key a few times before it runs some code before it. Here is the input thread: https://gist.github.com/EliterScripts/5 ... bd02d8f6ab here's the output thread: https://gist.github.com/EliterScripts/c ... 173e717cb3 Here's what loads the output thread: https://gist.github.com/EliterScripts/2 ... be60dc1917 and here's what loads the input thread: https://gist.github.com/EliterScripts/f ... 32f42e3eda
and so the input thread is loaded (using the require function) before the output thread, and here is the kind of weird stuff this is doing:
"
depended: game/server/index
depended: game/server/commandLineInput
depended: game/server/commandLineOutput
enabling Fancy CLI features...
Fancy CLI features enabled.
"
The part where is says "depended...." is the part that is normal, and is code that is run beforehand. I had to hit "enter" before "Fancy CLI features enabled." was printed, which is weird.
So I would like to use io.read() in my game, as it allows the user to input commands using the terminal approach. This is a great feature for my server edition of my game. However, I do not want to bring the entire game to a halt. I tried slapping io.read() on its own thread, and was planning on having a separate thread for printing console output.
However, my code is doing this strange thing where if I have 'io.read()' it will halt executing code before it, then I have to tap the 'enter' key a few times before it runs some code before it. Here is the input thread: https://gist.github.com/EliterScripts/5 ... bd02d8f6ab here's the output thread: https://gist.github.com/EliterScripts/c ... 173e717cb3 Here's what loads the output thread: https://gist.github.com/EliterScripts/2 ... be60dc1917 and here's what loads the input thread: https://gist.github.com/EliterScripts/f ... 32f42e3eda
and so the input thread is loaded (using the require function) before the output thread, and here is the kind of weird stuff this is doing:
"
depended: game/server/index
depended: game/server/commandLineInput
depended: game/server/commandLineOutput
enabling Fancy CLI features...
Fancy CLI features enabled.
"
The part where is says "depended...." is the part that is normal, and is code that is run beforehand. I had to hit "enter" before "Fancy CLI features enabled." was printed, which is weird.