Some error in code pls help

Hey guys sooo i ran into a error when i tried playing my game
Capture2

THIS HAPPENS WHEN I TYPE 1 OR 2

Here is my code

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

public class Hacker : MonoBehaviour
{

    // Game configriation data

    string[] Level1Passwords = { "items", "spices", "Water", "waiter", "food" };
    string[] Level2Passwords = { "credit", "money", "transfer", "account", "balance" };


    //Game Stats
    int level;
    string Password;
    enum Screen { MainMenu, Password, Win }
    Screen currentscreen;

    // Use this for initialization
    void Start()
    {
        ShowMenuscreen();
    }


    void ShowMenuscreen()
    {
        currentscreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("");
        Terminal.WriteLine("WHERE WOULD U LIKE TO HACK TODAY");
        Terminal.WriteLine("");
        Terminal.WriteLine("Press 1 to hack into a restarunt");
        Terminal.WriteLine("Press 1 to hack into an ATM");
        Terminal.WriteLine("");
        Terminal.WriteLine("ENTER YOUR SELECTION HERE -");
    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMenuscreen();

        }

        else if (currentscreen == Screen.MainMenu)
        {
            Runmainmenu(input);
        }
        else if (currentscreen == Screen.Password)
        {
            CheckPassword(input);
        }
    }

    void Runmainmenu(string input)
    {
        bool Isvalidnumber = (input == "1" || input == "2");
        if (Isvalidnumber)
        {
            int.Parse(input);
            Startgame();
        }

        else if (input == "menu")
        {
            ShowMenuscreen();
        }

        else
        {
            Terminal.WriteLine("Error chose a valid operation");
        }
    }
    void Startgame()
    {
        currentscreen = Screen.Password;
        Terminal.ClearScreen();
        switch (level)
        {
            case 1:
                Password = Level1Passwords[Random.Range(0, Level1Passwords.Length)];
                Debug.Log(Password);
                break;

            case 2:
                Password = Level2Passwords[Random.Range(0, Level2Passwords.Length)];
                break;

            default:
                Debug.LogError("Error u have chosen a invalid level");
                break;
        }

        Terminal.WriteLine("Waiting for a password");
    }



    void CheckPassword(string Input)
    {
        if (Input == Password)
        {
            Displaywinscreen(); ;
        }
        else
        {
            Terminal.WriteLine("Wrong password try again");
        }
    }

    void Displaywinscreen()
    {
        currentscreen = Screen.Win;
        Terminal.ClearScreen();
        ShowWellDone();
    }

    void ShowWellDone()
    {
        switch (level)
        {
            case 1:
                Terminal.WriteLine("Have a slice plsss...");
                Terminal.WriteLine(@"
                
                        ___
                        |  ~~--.
                        |%=@%%/
                        |o%%%/
                     __ |%%o/
               _,--~~ | |(_/ ._
            ,/'  m%%%%| |o/ /  `\.
           /' m%%o(_)%| |/ /o%%m `\
         /' %%@=%o%%%o|   /(_)o%%% `\
        /  %o%%%%%=@%%|  /%%o%%@=%%  \
       |  (_)%(_)%%o%%| /%%%=@(_)%%%  |
       | %%o%%%%o%%%(_|/%o%%o%%%%o%%% |
       | %%o%(_)%%%%%o%(_)%%%o%%o%o%% |
       |  (_)%%=@%(_)%o%o%%(_)%o(_)%  |
        \ ~%%o%%%%%o%o%=@%%o%%@%%o%~ /
         \. ~o%%(_)%%%o%(_)%%(_)o~ ,/
           \_ ~o%=@%(_)%o%%(_)%~ _/
             `\_~~o%%%o%%%%%~~_/'
                `--..____,,--'



     
                                   ");
                break;
        }
    }
}

Hi Nihal,

What value does level have when the Startgame method gets called? Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Hehe i am a noob when it comes to coding and…

i dint understand by the term value i compared my code to lecture code changes(only the startgame method tho) it seems to have no difference? (again i dint check the whole code)

Log level into your console to see its value.`

And check the rest of your code code. For example, where in your code do you assign a value to level? And where does the instructor in the video do that?

Thanks… i compared the text to the code provided by them and saw a slight error.

:v::ok_hand::v::ok_hand::v::+1::+1::+1:

I’m glad you spotted it. Well done. :slight_smile:

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

Privacy & Terms