`Terminal' does not contain a definition for `ClearScreen'?

Hi there,

I just got to the point of making some ASCII art, but now I’m getting this error and my game won’t run

Terminal' does not contain a definition forClearScreen’

???

The error appears in the console three times - so every time I have the Terminal.ClearScreen(); in the code, it’s rejecting it.

I’m writing Terminal.ClearScreen(); the same way as the video, and it’s been working fine up til now, so I’m stumped. I don’t know what I could have changed that would have broken it, does anyone have any ideas?

Thank you!

1 Like

Could you copy/paste your full Hacker.cs script into your reply?


See also;

I think I’ve got it working now. When it started throwing up the error, I right clicked the Terminal.ClearScreen where it was getting underlined in red, and think I accidentally clicked on some kind of autocorrect thing in Visual Studio. I think it added something to the Terminal.cs code - is this possible? Anyway, it was no longer the same as the source on github, so I copy-pasted the github code back into my Terminal.cs file and the error went away.

1 Like

Glad to hear you have resolved the issue and can move forward again :slight_smile:

Thanks for replying so quickly, Rob. I’m not sure what happened there, but it seems okay now… fingers crossed I can finish the project!

1 Like

No problem at all. It’s a bit hard to suggest what it might have been without seeing what happened/steps to reproduce etc.

I’m sure you’ll complete the project, and be sure to share it with the community when you have! :slight_smile:

Hello! This error is happening again.

It seems to be triggered when I extract a method in Visual Studio. For some reason, this doesn’t work in the way that it does in the video - when I highlight the code I want to extract and right click > extract, it doesn’t go automatically to the name of the new method… for some reason it seems to be selecting Terminal instead, and then the ClearScreen becomes an error.

I poked around and it seems that when I extract the method it’s renaming this method in Terminal.cs to the name of the method I’m trying to extract?!

public static void ClearScreen()
    {
        primaryTerminal.displayBuffer.Clear();
    }

I’m using a Mac. What’s going wrong here?

Here is the code from my Hacker.cs file:

using UnityEngine;

public class Hacker : MonoBehaviour {

    // Game configuration data

    string[] level1passwords = { "bookmark", "shelf", "loan", "hardback", "nap" };
    string[] level2passwords = { "officer", "siren", "handcuffs", "complaint", "donuts", "arrest" };
    string[] level3passwords = { "rocket", "planet", "comet", "asteroid"};

    // Game states

    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 the local library");
        Terminal.WriteLine("Press 2 for the police station");
        Terminal.WriteLine("Press 3 for NASA");
        Terminal.WriteLine("Type menu at any time to return to the start");

    }
    // the user presses a key here, so the computer runs OnUserInput
    // OnUserInput checks which screen we're on
    // If we're on the Main Menu screen, it checks for a level selection - using RunMainMenu
    // If we're already on a level, it checks for a password - using CheckPassword


    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMainMenu();
        }
        else if (currentScreen == Screen.MainMenu)         
        {
            RunMainMenu(input);
        }
        else if (currentScreen == Screen.Password)
        {
            CheckPassword(input);
        }
    }


    void RunMainMenu(string input)
    {

        bool isValidLevelNumber = (input == "1" || input == "2" || input == "3"); // defines valid levels
        if (isValidLevelNumber)
        {
            level = int.Parse(input); // turns the input into an integer
            AskForPassword();
        }
        else
        {
            Terminal.WriteLine("Not an option, sorry");
        }
    }

    void AskForPassword()
    {
        currentScreen = Screen.Password;
        Terminal.ClearScreen();
        SetRandomPassword();
        Terminal.WriteLine("Enter the password, hint: " + password.Anagram());
    }

    void SetRandomPassword()
    {
        switch (level)
        {
            case 1:
                password = level1passwords[Random.Range(0, level1passwords.Length)];
                break;
            case 2:
                password = level2passwords[Random.Range(0, level2passwords.Length)];
                break;
            case 3:
                password = level3passwords[Random.Range(0, level3passwords.Length)];
                break;
            default:
                Debug.LogError("invalid level number");
                break;
        }
    }

    void CheckPassword(string input)
    {
        if (input == password)
        {
            DisplayWinScreen();
        }
        else
        {
            AskForPassword();
        }
    }

    void DisplayWinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        ShowLevelReward();
    }

    void ShowLevelReward()
    {
        switch (level)
        {
            case 1:
                Terminal.WriteLine("Correct! You get a free book!");
                break;
            case 2:
                Terminal.WriteLine("Correct! Have a GET OUT OF JAIL FREE card!");
                break;
            case 3:
                Terminal.WriteLine("Correct! You win a trip to Mars!");
                break;
        }

    }

    void Update () {
		
	}
}

Any chance you could do a quick screen record of what you’re doing?

What would be the best way to do that on a mac?

I am not familiar with Macs I’m afraid, so I’m not sure what software options are available to you, e.g. whether there is already anything installed/built in. If there isn’t, there is bound to be free options online. Alternatively, you could take screenshots of each step, might be a bit painful but perhaps quicker than searching for screen recording solutions.

I did however just find an article from 2014 which suggests that the Quck Time Player has a Screen Record feature, it’s under “New” on the menu apparently.

Can you download this?

video

Yeah, I have watched it now. Incidentally, you can just embed the videos into your posts :slight_smile:

Anyhoo…

I see what you mean, odd behaviour.

Try adding some white space before and after the code you are selecting and see if it does the same thing, e.g. carriage return after lines 77 and 92.

It is kind of working as it has created that method call NewMethod() which is what should be selected afterwards for you to then type over the top of to rename it to what you want. Instead it appears to be selecting all of the Terminal references.

I did check to see if these were perhaps already selected before you started, but they don’t appear to be. I don’t suppose you happened to be doing a search in the code prior to this for the word Terminal or anything like that? In fact I can see you weren’t as the search field is at the top of the recording…


Updated Sun Mar 18 2018 11:46

Other thoughts…

If it is getting confused with the line numbers, it could be worth checking that there aren’t any errors in the code, prior to trying the Extract Method feature, for example, are all of the opening/closing brackets/braces in place? Missing a closing brace can confuse the compiler as it doesn’t know where you code really ends. This could potentially enable the Extract Method feature to be basing it’s selection on what it thinks is the correct line number, but isn’t.

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

Privacy & Terms