I've got some errors and warnings

Hi Kevin,

Welcome to our community! :slight_smile:

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.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Maybe there is a misplaced character in your hacker class.

Hope this helps :slight_smile:


See also;

Thanks for the welcome, here is the code and the error and warnings are in the screen shoot

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

public class hacker : MonoBehaviour
{
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string password;

// Use this for intialization
void Start()
{
    ShowMainMenu();
}


void ShowMainMenu()
{
    currentScreen = Screen.MainMenu;
    Terminal.ClearScreen();
    Terminal.WriteLine("What would you like to do");
    Terminal.WriteLine("press 1 for the Post Office");
    Terminal.WriteLine("press 2 for the Police");
    Terminal.WriteLine("press 3 for the Armed Forces");
    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);
    }
   

}
void RunMainMenu(string input)
    {

    if (input == "1")
    {
        level = 1;
        password = "donkey";
        StartGame();
    }
    else if (input == "2")
    {
        level = 2;
        password = "easy";
        StartGame();
    }
    else
    {
        Terminal.WriteLine("Please select a valid level");
    }

        }



void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine("You have choosen level " + level);
        Terminal.WriteLine("please enter your password");
    }
    void CheckPassword(string input)
    { if (input== password)
        {
            Terminal.WriteLine("well done");
        }
    else
        {
            Terminal.WriteLine("Sorry, wrong password");
        }
    }
}

Thank you for posting your code. Please format it properly to increase its readability. At the moment, I cannot spot any issue in it. Double click on the error message to see to which line it refers. ShowMainMenu gets called in a few places in your code.

This topic was automatically closed after 6 days. New replies are no longer allowed.

Privacy & Terms