Im having an issues with arrays

So I definitely went a little bit on my own for this code but I was really proud of it for the solo challenge.
Now as I come to add the arrays I’m getting issues with them. Im not sure if this is due to the code I added prior or what, but I would love to understand why its happening.

Code for Hacker Terminal

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

public class Hacker : MonoBehaviour
{
//Game Configuration Data
string level1Passwords { “Sports”, “Car”, “Beer”, “Boobs”, “Sleep” };
string level2Passwords { “Studious”, “Excellent”, “Hardwork”, “Conference”, “Detention” };
string level3Passwords { “Starfield”, “Telescope”, “Environment”, “Exploration”, “Austronauts” };

//Game State
int level;
string password;
enum Screen { MainMenu, Password, Win};
Screen currentScreen;
void Start()
{
    ShowMainMenu();
}


void ShowMainMenu()
{
    currentScreen = Screen.MainMenu;
    Terminal.ClearScreen();
    Terminal.WriteLine("Hello Hacker, We've been watching you. Its time to prove your skills");
    Terminal.WriteLine("Please choose your test level. We will be watching your results closely");
    Terminal.WriteLine("Level 1: Dad's Laptop");
    Terminal.WriteLine("Level 2: Principal's Computer");
    Terminal.WriteLine("Level 3: NASA");
    Terminal.WriteLine("Enter the number of the level you wish to attempt: ");
}
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;
        StartGame();
    }
    else if (input == "2")
    {
        level = 2;
        StartGame();
    }
    else if (input == "3")
    {
        level = 3;
        StartGame();
    }
    else
    {
        Terminal.WriteLine("Please enter a valid option");
        Terminal.WriteLine("Valid options: 1, 2, 3, menu");
    }
}

void StartGame()
{
     currentScreen = Screen.Password;

    Terminal.WriteLine("You have chosen level: " + level);
    if (level == 1)
    {
        
        Terminal.WriteLine("Let's see what Dad does in his spare time, shall we?");
        Terminal.WriteLine("Preparing to hack into Dad's Laptop");
        SetPassword(level);
    }
    else if (level == 2)
    {
        Terminal.WriteLine("So your grades weren't so great, lets go fix them.");
        Terminal.WriteLine("Preparing to hack into Principal's Computer");
        SetPassword(level);
    }
    else if (level == 3)
    {
        Terminal.WriteLine("Time for the big leagues huh?");
        Terminal.WriteLine("Preparing to hack into NASA");
        SetPassword(level);
    }
}

void SetPassword (int level)
{
    if (level == 1)
    {
        password = level1Passwords[2];
        GuessPassword();
    }
    else if (level == 2)
    {
        password = level2Passwords[0];
        GuessPassword();
    }
    else if (level == 3)
    {
        password = level3Passwords[3];
        GuessPassword();
    }
}
void GuessPassword()
{
    if (level == 1)
    {
        Terminal.WriteLine("Hint: rebe");
    }
    else if (level == 2)
    {
        Terminal.WriteLine("Hint: dustisou");
    }
    else if (level == 3)
    {
        Terminal.WriteLine("Hint: nxeportloia");
    }
}

void CheckPassword (string input)
{
    if (input == password)
    {
        currentScreen = Screen.Win;
        Terminal.WriteLine("Congradulations! You've Hacked In!");
    }
    else
    {
        Terminal.WriteLine("Incorrect! Try Again!");
    }
}

}

the specific compiling error is "CS0548 Hacker.Level1Passwords {} property or indexer must have at least one accessor

Hi! Welcome to the community!

The error occurs because you forgot to add the “=” symbol after the variable’s name, it should look like this.

string level1Passwords = { “Sports”, “Car”, “Beer”, “Boobs”, “Sleep” };
string level2Passwords = { “Studious”, “Excellent”, “Hardwork”, “Conference”, “Detention” };
string level3Passwords = { “Starfield”, “Telescope”, “Environment”, “Exploration”, “Austronauts” };

Ty so much

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

Privacy & Terms