I was just wondering if you could quickly answer a question for me. I'm doing a text adventure game, and I'm trying to have the player set their name in the main area, and store that to a variable and use it throughout other methods.
public static void Main(string[] args)
{
//intro
System.Console.WriteLine("Welcome to TextAdventure!");
System.Console.WriteLine("This is an entry level program made by JussaPeak");
System.Console.WriteLine("commands will be noted in the text by (). enter an applicable choice.");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine("Please enter your name:");
string name = Convert.ToString(Console.ReadLine());
System.Console.WriteLine(" ");
System.Console.WriteLine("Hello, {0}. You are about to embark on a lackluster journey of my first text adventure. i hope you enjoy!", name);
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
StartingArea();
}
public static void GypsyConvo2()
{
Console.WriteLine("You decide to stay and hear her out");
Console.ReadKey();
Console.WriteLine("{0}: Who is this person?", name);
Console.ReadKey();
Console.WriteLine("Gypsy: He is the shapeshifting king from the mountain in the west. His land is untouched by ours.");
Console.WriteLine("'I believe he is plotting to take our land...'");
Console.ReadKey();
Console.WriteLine(" ");
Console.WriteLine("{0}: and what am i to do about that?", name);
Console.ReadKey();
Console.WriteLine("Gypsy: You must warn the queen. i've found an old sewer maintainence that can lead near the entrance to the castle itself. You'll have to find your own way from there.");
}
So how would i make it so the variable that's being assigned a value from ReadLine in main, usable in other methods without it throwing me errors?