0
\$\begingroup\$

I'm writing a simple text-based adventure in lua. The intent is the user clicks on the game.exe and it loads up the command prompt or whatever command shell they have and they play the game there.

A problem I'm having is I often want to display a small amount of text at a time so the ui isn't overflowing with chunks of words. So I'm requiring the user to input something, preferably enter, to scroll through to the next bit of text.

i.e.

print("I want you to go to the park for a bit to start out.")
io.read()
print("After a few minutes I'll contact you, can you do that? (yes/no)") 
confirm=io.read()

I've been using a blank io.read() which will ask for user input and allow them to type characters and require them to hit enter, but not save what they wrote if anything. The intent is for the user not to write anything though and just hit enter, and only to write when they are given choices in brackets as seen in the second half. I feel like this is confusing and unintuitive, I was wondering if there was a simple better method. I see there are better languages for writing text based adventures, but I want to just stick to lua atm. If there is advice from another language, I can try and translate it over although you'd probably have a better idea of how. Examples are appreciated if there is a lua solution. Ideally I'd want to prevent input outside of pressing enter to scroll through text, or a timer so the next bit of text displays with some delay if that's possible for a simple windows shell like command prompt.

\$\endgroup\$
0
\$\begingroup\$

This is not a super complete answer, but here goes:

When you expect your player to hit any key to continue, the classic way to tell them is end the prompt with "Hit any key to continue".

Now to get only one character, it seems Lua allows to specify the amount of characters to read with read funcion, so just read one character:

print("I want you to go to the park for a bit to start out. (Hit any key to continue.)")
io.read(1)
print("After a few minutes I'll contact you, can you do that? (yes/no)") 
confirm=io.read()

I'm not familiar with Lua and this is untested code. This post helped.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.