Resolved Deleting a user's inputs?

the_Waterleaf

Member
Joined
Nov 6, 2021
Messages
9
Programming Experience
Beginner
I've gotten quite a bit done since my last question here, but I recently realised that the user can input all the text at the wrong time, so if the program prompted them for a name, then to answer a yes or no question they could just write both answers way before they are prompted to and I was wondering if there are any ways to access the place where their inputs are buffered in and clear that, all I could find online was how to delete something that's already been stored as a string, but doing that would just make their answers empty, not undo them answering in the first place, any ideas?
 
Perhaps yuppie could actually explain how the data is getting into the app in the first place. We can't tell you how to make something better if we don't know what it is to begin with.
 
As it is a console application, you would normally call Console.WriteLine to prompt the user and then call Console.ReadLine to get their response. You would then validate that response and assign the result to an appropriate variable. The user can't populate a variable unless you provide such an assignment.
 
Details! Either you're doing it right or you're doing it wrong. You seem to think it's the latter so show show us what you're doing so we can see what's wrong with it. Explain the specifics of what you're trying to achieve so we can see where the code fails to specifically do it.
 
I'm not doing it wrong because I'm just straight up not doing it at the moment, because I don't know how to actually access that input itself, all I can do is access the string which the input was turned into and if I do that and clear that then the response is still going to print out but it's gonna be empty, the actual string I assign the answer to is created right before the answer is needed and yet it functions as if it exists constantly, allowing them to type things out, which then get turned into the string, despite it tehnically not existing yet
This is what I am currently doing:
Console.WriteLine("Hello");
Console.WriteLine("You have accessed (name of the program)");
Console.WriteLine("Please input your name:");
string playerName = Console.ReadLine();
Console.WriteLine("Are you sure this is the name you want to use?");
string yesOrNo Convert.ToString(Console.ReadKey);
the first few lines actually have some sleeps inbetween each word to make it feel like it's actually being typed, but, while that is still being done, the user can already type out the name they want, enter it in, then the answer to that second prompt and enter that in too, despite neither variables existing while the text is still being written
 
Someone in a discord server helped me with this, it turns out all I needed was
while(Console.KeyAvailable) { Console.ReadKey(true); }
 
That will take all the inputs the player has stored up and delete them until there aren't any anymore, place all that into a method and call it right before you're supposed to take their input and done, they'll have to wait until they are prompted for it
 
That's terrible. Why force the user to go at the pace of your program when they can touch type faster than your code is running?
 
It's a game, you shouldn't be able to break order like that, unless I want you to, which is something I will allow the player to do in the right circumstances
 
If that's that case, then why use ReadLine()? Why not pull in the characters from the user as they are typing things using KeyAvailable and ReadKey(l?

I ask because I used to think the same way about my console games regarding input. I also wanted there to be a sound and visual effect as they typed in each key for their input.

In the end, I figured out that doing all that extra stuff is not where the quality of a console game comes from, but rather the content itself. Console games don't need a fully immersive experience in terms of UI. It's what's I help conjure in the minds of the player that provides the immersive experience.

Anyway, back to your original question. The appropriate question was "how to clear in the input buffer?"
 
I already have the whole thing figured out story wise, now it's just a matter of realising my vision, including making the game feel good with all that polish you mentioned
 
Back
Top Bottom