Hello there! I was following along this episode, and I ran into a problem, I hit 2 errors on my switch (Code below). the two errors report “A constant Value is expected” and “; expected”.
Where errors are:
switch(level)
{
case: 1
password = l1pass[0];
break;
case: 2
password = l2pass[0];
break;
default:
Debug.LogError("");
break;
}
The full code is here:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour {
public string greeting = "Hello There (Obi-Wan)";
string password;
enum Screen { MainMenu, Password, Win};
Screen currentScreen;
int level;
int ie = 0;
string[] l1pass = { "store", "river", "shop", "pond", "house" };
string[] l2pass = { "keys", "phone", "wallet", "bag" };
// Use this for initialization
void Start () {
ShowMainMenu();
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine(greeting);
Terminal.WriteLine("-----------------------------");
Terminal.WriteLine("Please Select Difficulty:");
Terminal.WriteLine("Press 1 for Home");
Terminal.WriteLine("Press 2 for Boss's Workstation");
Terminal.WriteLine("Press 3 for CEO's Desktop");
Terminal.WriteLine(" ");
Terminal.WriteLine("Input: ");
}
void OnUserInput(string input)
{
if(input == "menu")
{
ShowMainMenu();
}
if(currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
if(currentScreen == Screen.Password)
{
}
}
private void RunMainMenu(string input)
{
bool isValidLevelNumber = (input == "1" || input == "2" || input == "3");
if(isValidLevelNumber)
{
level = int.Parse(input);
StartText();
} else
if (input == "1")
{
level = 1;
print("Difficulty 1 Loading");
StartCoroutine(StartText());
}
else
if (input == "2")
{
level = 2;
print("Difficulty 2 Loading");
StartCoroutine(StartText());
}
}
public IEnumerator StartText()
{
Terminal.ClearScreen();
Terminal.WriteLine("Loading C:Users/Samuel/");
yield return new WaitForSeconds(1f);
Terminal.WriteLine("...");
yield return new WaitForSeconds(1f);
Terminal.WriteLine("Please wait while system is booting up");
yield return new WaitForSeconds(5f);
Terminal.WriteLine(" ");
Terminal.WriteLine("Welcome back Samuel. Please enter your password to begin.");
yield return new WaitForSeconds(3f);
Terminal.WriteLine(" ");
Terminal.WriteLine("Input: ");
Terminal.WriteLine("KittyKat112");
yield return new WaitForSeconds(.5f);
Terminal.WriteLine(" ");
Terminal.WriteLine("Password incorrect (2/3) Remaining");
yield return new WaitForSeconds(3f);
Terminal.ClearScreen();
Terminal.WriteLine("That was incorrect. Please re-enter your password to begin. (2/3)");
Terminal.WriteLine(" ");
Terminal.WriteLine("Input: ");
Terminal.WriteLine("Jaguar22");
yield return new WaitForSeconds(.5f);
Terminal.WriteLine(" ");
Terminal.WriteLine("Password incorrect (1/3) Remaining");
yield return new WaitForSeconds(3f);
Terminal.ClearScreen();
Terminal.WriteLine("That was incorrect. Please re-enter your password to begin. (1/3)");
Terminal.WriteLine(" ");
Terminal.WriteLine("Input: ");
Terminal.WriteLine("Jessica1012");
yield return new WaitForSeconds(.5f);
Terminal.WriteLine(" ");
Terminal.WriteLine("Password incorrect (0/3) Remaining");
yield return new WaitForSeconds(1f);
Terminal.ClearScreen();
Terminal.WriteLine("Too many attempts wrong, ignitiating");
Terminal.WriteLine("backup program.");
yield return new WaitForSeconds(3f);
Terminal.WriteLine(" ");
Terminal.WriteLine("ljsby ojsra wsgcr cffvm xqewn dspjl etzph lmejp qgzqz jhlhl tnklb ztmiv");
Terminal.WriteLine("daffw vbrdv hmpvv s");
Terminal.WriteLine(" ");
Terminal.WriteLine("Decripting...");
yield return new WaitForSeconds(3f);
Terminal.WriteLine("Finalizing");
yield return new WaitForSeconds(3f);
Terminal.ClearScreen();
switch(level)
{
case: 1
password = l1pass[0];
break;
case: 2
password = l2pass[0];
break;
default:
Debug.LogError("");
break;
}
currentScreen = Screen.Password;
}
}
Thanks for the help!