Therminal Hacker Error


I cant figure out how to fix these two errors, they don’t show on the visual studio

Hi,

The yellow messages are harmless warnings, probably caused by a bug in Unity. Double click on each message in your Console, and add = default; behind the variable declaration.

The red ones are “dangerous”. Make sure your curly brackets are placed correctly. Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

Yes I have already compared the code. I cant see anything that is wrong with it either. The errors wont show on visual studio, if you want i can send you screenshots of my code.

Did you do what I suggested to remove the yellow messages?

You could paste your code here and format it if you cannot spot the problems the red error messages are talking about.


See also:

I dont know what to do, so here is my code:

class Hacker : MonoBehaviour
{

int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string password;

void Start()
{
    ShowMainMenu();
}

void ShowMainMenu()
{
    currentScreen = Screen.MainMenu;
    Terminal.ClearScreen();
    Terminal.WriteLine("What Would You Like To Hack Into?");
    Terminal.WriteLine("Press 1 for School System");
    Terminal.WriteLine("Press 2 for Local Hospital");
    Terminal.WriteLine("Press 3 for US Internet");
    Terminal.WriteLine("Enter Your Selection: ");

}

private void RunMainMenu(string input)
{
    if (input == "menu")
    {
        ShowMainMenu();
    }

    else if (currentScreen == Screen.MainMenu)
    {
        RunMainMenu(input);
    }
    else if (currentScreen == Screen.Password)
    {
        CheckPassword(input);
    }



    void RunMainMenu(string input)
    {
        if (input == "1")
        {
            level = 1;
            password = "hallpass";
            StartGame();

        }
        else if (input == "2")
        {
            level = 2;
            password = "cancer";
            StartGame();
        }
        else if (input == "Hoos03")
        {
            Terminal.WriteLine("Hello Mr Pedro");
        }
        else
        {
            Terminal.WriteLine("Please Choose A Valid Level");
        }
    }

    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine("You Have Chosen Level " + level);
        Terminal.WriteLine("Please Enter Your Password:");
    }

    void CheckPassword( string input )
    {
        if (input == password)
        {
            Terminal.WriteLine("Congrats, You Won!");
        }
        else
        {
            Terminal.WriteLine("Incorrect! Ask Again");
        }

    }


}

}

Looks like you’re missing a curly bracket under the first RunMainMenu method. Also I dont think you can have two methods with the same name.

Regarding the yellow error messages, try this, please:

Screen currentScreen = default;
string password = default;

Regarding the red ones, please try what @David_Lamonaca suggested.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms