Visual Studios is saying my variable is undefined for some reason.

omatamix

New Member
Feb 20, 2019
18
6
Hey for some reason visual studios is saying variable score is undefined but looking at the code, I can't see why it would not be set. Here is my code below.

C++:
int reduction = 1;
if (moveCount == 0) {
    Score score = -search(position.makeMove(move), -beta, -alpha, depth - reduction, ply + 1);
} else {
    if (moveCount > 3 && !(move.bit & 2)) reduction = 3;
    Score score = -search(position.makeMove(move), -alpha - 1, -alpha, depth - reduction, ply + 1);
    if (alpha < score < beta) {
        score = -search(position.makeMove(move), -beta, -score, depth - reduction, ply + 1);
    }
}
if (score >= beta) { // Says score is undefined.

}

How is that possible because the score variable is set no matter which way the if statement goes. Is this an error on visual studios?
Post automatically merged:

I solved this by defining score before the if statement, but shouldn't this work as well?
 
Last edited:
Solution
It's because

"score" is not inside the scope, as u have put them inside the conditions above

"I solved this by defining score before the if statement, but shouldn't this work as well?"

It should / would not work if u dont define it in an accesible way within your scope

Object

?
Nov 10, 2017
412
325
It's because

"score" is not inside the scope, as u have put them inside the conditions above

"I solved this by defining score before the if statement, but shouldn't this work as well?"

It should / would not work if u dont define it in an accesible way within your scope
 
Last edited:
Solution

Users who are viewing this thread

Top