Im getting a non defined variable error, but every other place compiles fine?

So, in my code, im making a little game about reaction timing, and I have an error about a non declared variable on the fourth if statement, but on the three previous if statements it compiled fine, I will put the loop and the function with the error

void flashLight() {
  //4 if statements running at same time to check what number the random produced
  if (randomLight == 1) {
    digitalWrite(light1, HIGH);
    bu1 = 1;
  }
  if (randomLight == 2) {
    digitalWrite(light2, HIGH);
    bu2 = 1;
  }
  if (randomLight == 3) {
    digitalWrite(light3, HIGH);
    bu3 = 1;
  }
  if (randomLight == 4) {
    digitalWrite(light4, HIGH);
    bu4 = 1;
  }
}

Function ^^^
Loop ///

void loop() {
  int randomLight = random(1, 4);
  flashLight();
  beginCountdown();
  // put your main code here, to run repeatedly:

}

Error /

exit status 1
'randomLight' was not declared in this scope

I dont know why tho, bye for now!

int randomLight
make this a global variable.

You declared a local variable named 'randomLight' in loop().

The variable named 'randomLight' in flashLight() is not declared.

Sounds like you want to declare 'randomLight' as a GLOBAL varible, outside any function, so it can be used to communicate between the two functions that use it.

oh my god, thanks, didnt realize that, heh heh, thanks!

I was also told that you only put the variable ontop of the if statement when you are using

SkyCrafter:
I was also told that you only put the variable ontop of the if statement when you are using

Could you repeat that in English?

Steve

You should read the documentation on the random() function. random(1,4) will sort-of-randomly return 1, 2, or 3. There is no sense in testing that the value is 4.

PaulS:
You should read the documentation on the random() function. random(1,4) will sort-of-randomly return 1, 2, or 3. There is no sense in testing that the value is 4.

Thanks, I never quite read it to the fullest

SkyCrafter:
I was also told that you only put the variable ontop of the if statement when you are using

Could you repeat that in English?

Steve
ENGLISH: I was also told that you only put the variable ontop of the if statement when you are using

SkyCrafter:
Steve
ENGLISH: I was also told that you only put the variable ontop of the if statement when you are using

Thanks, that clears it up nicely apart from just a couple of little things...what does "ontop of the if statement" mean? Oh and "when you are using" what? Heroin? A big hammer? Something else?

The individual words are mainly English, but the sentence is meaningless.

Steve

yeah it is, I didnt quite finish it,
Ontop = Line above
When you are using if statement