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
Plerx
Plerx10mo ago
No description
Keswiik
Keswiik10mo ago
$details
MODiX
MODiX10mo ago
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
Plerx
Plerx10mo ago
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!
Keswiik
Keswiik10mo ago
just copy-paste your code in here or the website linked $code
MODiX
MODiX10mo ago
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?
Keswiik
Keswiik10mo ago
Why is copy-pasting your code an issue? Most people aren't going to hop in VC to help you.
𝐏𝐑𝐎𝐃𝐈𝐆𝐈𝐄𝐒 ❗
I thought itd be an error because I have multiple classes
Keswiik
Keswiik10mo ago
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
Keswiik
Keswiik10mo ago
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
Keswiik
Keswiik10mo ago
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 something
𝐏𝐑𝐎𝐃𝐈𝐆𝐈𝐄𝐒 ❗
Where do I not have the readline i thought i was spamming it 😂
Keswiik
Keswiik10mo ago
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?");

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();

}
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?");

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();

}
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?
Keswiik
Keswiik10mo ago
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?
Keswiik
Keswiik10mo ago
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?
Keswiik
Keswiik10mo ago
Variables that are declared within a method (or lambdas, etc).
public class Example {

private string field;

public string Property { get; set; }

public void SomeMethod() {
string localVariable = "idk";
}
}
public class Example {

private string field;

public string Property { get; set; }

public void SomeMethod() {
string localVariable = "idk";
}
}
𝐏𝐑𝐎𝐃𝐈𝐆𝐈𝐄𝐒 ❗
why do you advise against class fields
Keswiik
Keswiik10mo ago
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
Keswiik
Keswiik10mo ago
Take a careful look at your class, you have extra Console.ReadLine() calls thrown in randomly.
𝐏𝐑𝐎𝐃𝐈𝐆𝐈𝐄𝐒 ❗
I think I found it
Want results from more Discord servers?
Add your server