Got it to work

            case 1:
                int index = Random.Range(0, level1Passwords.Length);
                password = level1Passwords[index];
                break;
            case 2:
                index = Random.Range(0, level2Passwords.Length);
                password = level2Passwords[index];
                break;

Ran into a bit of confusion with index already being defined but didn’t want to make a new variable for each of the difficulties as I thought it could get a little messy. Solved my issue by just putting in index without int behind it so it’s not being defined again. Fun challenge overall.

1 Like

Hi Lemint,

It would be best to declare the variable outside of those cases, currently, it’s only declared within case 1, but then used without being declared in case 2.

Example;

int index;  // declared outside of switch cases

switch(level)
{
    case 1:
	    index = Random.Range(0, level1Passwords.Length);
	    password = level1Passwords[index];
	    break;
    case 2:
	    index = Random.Range(0, level2Passwords.Length);
	    password = level2Passwords[index];
	    break;
}

Hope this helps :slight_smile:

Privacy & Terms