Terminal.Writeline duplicates and CurrentScreen unchanged

I am having a few issues with my code so laid it out side-by-side with that in the video to comb through for differences, walked away then combed through again (several times) and I just can’t spot where I have gone wrong! I am hoping somebody can help me. Below is my code and an image of the issues I am seeing when I play the game in Unity.

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

public class Hacker : MonoBehaviour
{
// Game configuration data
string level1Passwords = {“Red”, “Rabbit”, “Pink”, “Robots”, “Fish”, “Marble”};
string level2Passwords = { “Sausage”, “Beer”, “Wotsits”, “Worker”, “Mash”, “Koala” };

//Game State
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string Password;


void Start()
{
    ShowMainMenu();
}

void ShowMainMenu()
{
    currentScreen = Screen.MainMenu;
    Terminal.ClearScreen();
    Terminal.WriteLine("The government has been lying to us.");
    Terminal.WriteLine("Find their secrets.");
    Terminal.WriteLine("Who would you like to hack first??");
    Terminal.WriteLine("Press 1 for the local library");
    Terminal.WriteLine("Press 2 for the local cop shop");
}

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)
{
    bool isValidLevelNumber = (input == "1" || input == "2");
    if (isValidLevelNumber)
    {
        level = int.Parse(input);
        StartGame();
    }
    else if (input == "wtf") // easter egg
    {
        Terminal.WriteLine("Back up buster");
    }
    else
    {
        Terminal.WriteLine("Choose a bloody number");
    }

}

void StartGame()
{
    currentScreen = Screen.Password;
    Terminal.ClearScreen();
    switch(level)
    {
        case 1:
            Password = level1Passwords[0];
            break;
        case 2:
            Password = level2Passwords[2];
            break;
        default:
            Debug.LogError("Invalid level number");
            break;
    }
    Terminal.WriteLine("Please enter your password");
}
void CheckPassword(string input)
{
    if (input == Password)
       {
       Terminal.WriteLine("Well done spoon!");
       }
    else
       {
       Terminal.WriteLine("You're an idiot. Try again.");
       }
}

}

Hi Billie-Louise,

First of all, add a Debug.Log to your CheckPassword method and log input into your console. How many times does the message get logged into your console?

Also log currentScreen into your console.

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

Privacy & Terms