NotImplementedException: The method or operation is not implemented

hello i am trying to make my game read passwords the passwords are there in the debugger but when i type it in it just duplicates and says the error above any tips or trick that can help me? here is my code

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.Cryptography;
using UnityEngine;

[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + “(),nq}”)]
public class Hacker : MonoBehaviour {

// Game state
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string password;
// Use this for initialization
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("Enter your selection:");
}
void OnUserInput(string input)
{
    if (input == "menu")
    {
        ShowMainMenu();
    }
    else if (currentScreen == Screen.MainMenu)
    {
        Runmainmenu(input);
    }
    else if (currentScreen == Screen.Password)
    {
        Checkpassword(input);

    }
}

private void Checkpassword(string input)
{
    throw new NotImplementedException();
}

void CheckPassword(string input)
{
    if (input == password)
    {
        checkpassword(input);
        Terminal.WriteLine("Sorry, wrong password!");
    }
    else
    {
        Terminal.WriteLine("WELL DONE!");


    }


}

private void checkpassword(string input)
{
    Checkpassword(input);
}

private void Runmainmenu(string input)
{
    {
        if (input == "1")
        {
            level = 1;
            password = "book";
            StartGame();
        }
        if (input == "2")
        {
            level = 2;
            password = "handcuffs";
            StartGame();
        }
        else if (input == "007")
        {
            Terminal.WriteLine("Please select a level Mr Bond!");
        }
        else
        {
            
        }
    }
}

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



string GetDebuggerDisplay()
{
    return ToString();
}

}

Why do you have 3 methods named almost exactly the same?

The one throwing the error is this one:

private void Checkpassword(string input)
{
    throw new NotImplementedException();
}

I highly suggest you clean your code by comparing it with Ben’s code, you can access it in the lesson resources.

i did that it now says the name checkpassword does not exist in the current context x2

The x2 is probably because you have another object with the same script.

Remember that the code is case sensitive, in your OnUserInput you are calling for “Checkpassword” not “CheckPassword”, if you are new to coding I highly suggest you copy paste your methods so you don’t end with this kind or errors.

thanks that worked! but now i am getting a stack overflow error

void CheckPassword(string input)
{
    if (input == password)
    {
        checkpassword(input); // <-- Erase this line
        Terminal.WriteLine("Sorry, wrong password!");
    }
    else
    {
        Terminal.WriteLine("WELL DONE!");


    }


}

private void checkpassword(string input)//Erase this method
{
    Checkpassword(input);
}

You are calling the same method an infinite amount of times, that’s what causing the stack overflow.

nvm

This line here:

checkpassword(input);

now i got another error the name checkpassword does not exist in current context but only on tho

Check your code and see where you are calling “checkpassword” and change it to “CheckPassword”.

I also suggest to check and compare your code with Ben’s, I don’t even know why you have two extra namespaces, your code is kinda messy.

Ok thank you for all your help but how do i find out whats calling it tho

If you did exactly what I told you, you shouldn’t have that error unless you added lines or didn’t use the correct method’s name, so I can’t keep helping unless you copy/paste your code again here.

Try to keep you code as clean as possible all the time so you know exactly what is going on, if you don’t fully understand coding yet I highly suggest you keep your code as close as Ben’s code as possible.

Are you doing the solo challenge?

yep

sorry i just reread your post there is no errors now

1 Like

it takes the input as the password instead of the password wich is book any idea why?

I don’t fully understand your question, What do you mean by it’s taking the input instead of the password?

The code, according to what you posted, is working exactly as intended, if you select level 1 the password should be “book”, if you select level two the password should be “handcuffs”.

so what i mean by that is that if i press 1 i programmed it to say you have chosen level one
and if i type in my password wich is book it says wrong password but if i type one it is right even the debugger says book is the right password.

never mind it was case sesitvive thank you for all your help

1 Like

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

Privacy & Terms