Pls help there is error in my password section

EVEN AFTER ENTERING THE CORRECT PASSWORD I M STUCK INSIDE THE PASSWORD SECTION PLS HELP!!

this is my output


this is my input

In your checkpassword method the only thing you are doing is entering a terminal line, you are not returning to the main menu.

You must find a way to return to the main menu after the player entered the correct password. According to your code, you only require to write a single line to do that.

Don’t get too frustrated with this, this first Solo Challenge is quite hard, if you don’t get it at first just keep trying, if you still don’t get it don’t worry, you are in the majority.

Edit: I almost forgot something really important.
Naming conventions, try to name your methods with upper case letters

Example:

  • Instead of" startgame" name it “StartGame”
  • Instead of “checkpassword” name it “CheckPassword”

This makes everything easier to read and also avoids syntactic conflicts with your variables, enums, and more.

1 Like

i am not able to understand it i did this
Example:

  • Instead of" startgame" name it “StartGame”
  • Instead of “checkpassword” name it “CheckPassword”
    But same output is coming…

Hi Jayprakash,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Hope this helps :slight_smile:


See also;

2 Likes

That won’t fix your issue nor it will change anything in your code, that’s just for good practice, methods’ names should never be written with lower case letters.

If you want the solution to your problem (if you still have it), I’ll give it to you, just next time try to do it for yourself, you’ll learn far more that way.

void CheckPassword()
{
    if(i == password)
    {
        Terminal.WriteLine("Well Done");
        mainmenu(); //<=== Add this line of code
    }
    else
        Terminal.WriteLine("SORRY, WRONG PASSWORD");
}

That should fix your problem, unfortunately I can’t do anything else, as Nina said, it’s hard to test this out without being able to copy-paste the code.

1 Like

SEE THIS IS MY CODE I M STILL GETTING THE SAME ERROR EVEN AFTER APPLYING “MAINMENU();” IN THE CHECKPASSWORD SECTION

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

public class Hacker : MonoBehaviour
{
// Game state
int level;
enum Screen { Mainmenu, Password, win }
Screen CurrentScreen;
string Password;
// Start is called before the first frame update
void Start()
{

    print("hello console");
    Mainmenu();
}


void Mainmenu()
{
    Terminal.ClearScreen();
    Terminal.WriteLine("Stop being lazy!Tell me what u want to hack?");
    Terminal.WriteLine("1.Hack NASA");
    Terminal.WriteLine("2.HACK parul");
    Terminal.WriteLine("3.HACK swiss bank");
    Terminal.WriteLine("Enter your choice: ");
}
// Update is called once per frame
void OnUserInput(string i)
{
    if (i == "menu") //direct to the main menu
        Mainmenu();
    else if(CurrentScreen==Screen.Mainmenu)
    {
        Runmainmenu(i);
    }
    else if(CurrentScreen==Screen.Password)
    {
        CheckPassword(i);
    }
}

 void Runmainmenu(string i)
{
    if (i == "lohit")
        Terminal.WriteLine("hi buchki");
    else if (i == "1")
    {
        level = 1;
        Password = "right";
        StartGame();
    }
    else if (i == "2")
    {
        level = 2;
        Password = "left";
        StartGame();
    }
    else
        Terminal.WriteLine("invalid input");
}

 void StartGame()
{
    CurrentScreen = Screen.Password;    
    Terminal.WriteLine("You have selected level " + level);
    Terminal.WriteLine("Enter your password");
}

void CheckPassword(string i)
{
    if (i == Password)
    {
        Terminal.WriteLine("WELL DONE!!");
        Mainmenu();
    }
    else
    {
        Terminal.WriteLine("SORRY, WRONG PASSWORD!");
    }
}

}

1 Like

Yeah, now I see what is going on.

You forgot to change your CurrentScreen state in your MainMenu method.

void Mainmenu()
{
    CurrentScreen = Screen.Mainmenu; //Add this line
    Terminal.ClearScreen();
    Terminal.WriteLine("Stop being lazy!Tell me what u want to hack?");
    Terminal.WriteLine("1.Hack NASA");
    Terminal.WriteLine("2.HACK parul");
    Terminal.WriteLine("3.HACK swiss bank");
    Terminal.WriteLine("Enter your choice: ");
}
1 Like

thank you so much got it working

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

Privacy & Terms