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
Plerx3mo ago
No description
Keswiik
Keswiik3mo ago
$details
MODiX
MODiX3mo 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
Plerx3mo 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
Keswiik3mo ago
just copy-paste your code in here or the website linked $code
MODiX
MODiX3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
Keswiik3mo 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
More Posts
Starting off aid?Hey all. I'm just starting off with trying to learn C# with game development intentions, and hopefulmulti threaded gate lock ORUsing the Monitor class, is there a way to create a lock with n input values, which creates a lock ftrying to search through a ReportviewerI am unsure of what is wrong but when i try to search for a specific value and try to show the reporTrying to get a game object to disappear and re-appear when a certain number of items are collected.I have a game object that when you collide with it, it takes you to the next level, but i would likeAdvice on how to structure a windows form application where it takes images to generate cards?I am making a win form for my card battling game but i'm unsure how to make it actually put the userUnhandled exception. System.IO.FileNotFoundExceptionHi, so I am trying to publish my app to Azure and when i try to load the page it gives Application EUnable to calculate/store correct value to the dbHello. I am developing a mortgage tracker for myself and currently trying to calculate my daily inteReading nested dictionaries received via MQTTHi, so basically someone coded a script, which sends JSONs per MQTT. I want to receive them in UnityHow can i save `Textures, Shaders...` in my nuget packet?Hello, i try to save my textures and shaders in my nuget packet but it wont work that i what i triedunable to parse Json data pulled from API as a list of stringsI am trying to take some data from an API called Scryfall API and assign it to a List variable. I am