EVEN AFTER ENTERING THE CORRECT PASSWORD I M STUCK INSIDE THE PASSWORD SECTION PLS HELP!!
…
this is my output
this is my input
EVEN AFTER ENTERING THE CORRECT PASSWORD I M STUCK INSIDE THE PASSWORD SECTION PLS HELP!!
…
this is my output
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:
This makes everything easier to read and also avoids syntactic conflicts with your variables, enums, and more.
i am not able to understand it i did this
Example:
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
See also;
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.
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!");
}
}
}
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: ");
}
thank you so much got it working
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.