Statement not printing to screen
I have zero errors and I need to figure out why my code stops working after a certain point
29 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
I really dont know how to else to explain it bc its so weird to me
I can post pics here?
some servers have a problem with it so i just didnt show anything
Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
BlazeBin
A tool for sharing your source code with the world!
just copy-paste your code in here or the website linked
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/is it possible i can stream it?
Why is copy-pasting your code an issue? Most people aren't going to hop in VC to help you.
BlazeBin - crjayfodtepo
A tool for sharing your source code with the world!
I thought itd be an error because I have multiple classes
Not much of a problem, you can make individual pastes on the website or throw it all in the same one.
Now, what's the "certain point" your program stops working at?
And what are you expecting to happen?
The console closes after the switch explore statement
it doesnt put the if else condition with the writelines in it to screen
well, your first issue is
string input = Console.ReadLine()
- why are you initializing a field on your game class to a readline?
Also, do you ever get input from the user in your explore switch statement?No
I made it so it could capture the user input or is that wrong
That is wrong
Console.ReadLine()
needs to be called every time you want to check input from the user
In general, your program has to:
- print something to the console so the user knows what to do
- read the user's input
- do somethingWhere do I not have the readline i thought i was spamming it 😂
There is no readline between where you ask
Do you wish to pick it up?
and where you check input
You also have to assign the value you get from Console.ReadLine()
to a variable. Just calling it does nothing but read the console and discard the value you read.case "1":
Console.WriteLine("You walk through the double doors. You see something shiny in a corner.");
Console.WriteLine("Do you wish to pick it up?");
Console.ReadLine();
if (input == "yes")
{
Inventory inventory = new Inventory();
inventory.AddItem("Gold Pocket Watch");
Console.WriteLine("You've found a pocket watch!");
Console.WriteLine("There was nothing else valuable inside the building so you leave.");
Console.ReadLine();
}
so with the readline, do i put it there?
It's in the right spot now, but it's still not going to work. Read the last thing I sent.
is there where I assign input to the readline now?
Yup. But I'd advice against using a class field for user input. You can assign it to a new local variable.
whats a local variable? one thats already used?
Variables that are declared within a method (or lambdas, etc).
why do you advise against class fields
I am advising against class field for user input from the console, not in all cases
and it worked ty but I have one last minor problem. When I type 1 after the Choice case it makes me repeat it to get to the next writeline
oh okay
Take a careful look at your class, you have extra
Console.ReadLine()
calls thrown in randomly.I think I found it