Code not working after refactoring

Hi, im getting this error Right after letting the Programm make the new function “RunMainMenu”

This is the error:
Assets\WM2000\Hacker.cs(48,33): error CS0136: A local or parameter named ‘input’ cannot be declared in this scope because that name is used in an enclosing local scope to define a local or Parameter

Im thankful for any help!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour

{

int level;
string levelname;

enum Screen { MainMenu, WaitingForPassword, WinScreen };
Screen currentScreen = Screen.MainMenu;
// Start is called before the first frame update
void Start()
{
    ShowMainMenu("Hey Miku!");
}

void ShowMainMenu(string test)

{
    Terminal.ClearScreen();
    Terminal.WriteLine(test);
    Terminal.WriteLine("What would u like to hack into? uwu");
    Terminal.WriteLine("Press 1 for the Tom Nook Inc.");
    Terminal.WriteLine("Press 2 for the Valve Headquaders");
    Terminal.WriteLine("Enter youwr selection: ");

}

public void OnUserInput(string input)
{

    if (input == "menu")
    {

        ShowMainMenu("Hello again! c:");

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

    }

    void RunMainMenu(string input)

    {
        if (input == "1")

        {
            level = 1;
            levelname = ("Animal Crossing Tom Nook Inc.");
            StartGame();

        }

        else if (input == "2")
        {
            level = 2;
            levelname = ("Valve Headquaders");
            StartGame();
        }
        else if (input == "19.02")
        {
            Terminal.WriteLine("c:");
        }
        else
        {
            Terminal.WriteLine("Thats not a level, try again");
        }

        void StartGame()
        {
            currentScreen = Screen.WaitingForPassword;
            Terminal.ClearScreen();
            Terminal.WriteLine("You have chosen level " + level + (":\n") + levelname);
            Terminal.WriteLine("Please enter your password.");
        }
    }
}

}

Hi Mike,

Welcome to our community. The problem is the following: RunMainMenu is declared in the OnUserInput method because the closing curly bracket of the OnUserInput method is at the wrong place. Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

1 Like

Thank you, that helped!

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

Privacy & Terms