(solved) Variables not changing in if-then-else statement

Hi everyone i'm very new to programming and I can't seem to get past a seemingly simple task of changing variables.

Background:
I'm writing a simple program to control a motor driven door on a chicken coop; if a photoresistor detects the sun going down it closes the door, sun comes up door opens. The motor is controlled with an L293D H-Bridge. I've managed to experiment enough with the H-Bridge that i can get it to do what i want and as such i have omitted it from the code below for the sake of brevity.

int lightPin = 2; // photoresistor pin
int topPin = 4; // upper limit switch pin
int botPin = 2; // lower limit switch pin
int threshold = 560; // analogread voltage of photoresistor at night (higher is darker)

int partial = 0; // both limit switches depressed
int opened = 0; // upper limit switch depressed
int closed = 0; // lower limit switch depressed
int missing = 0; // no limit switches depressed
int dark = 0; // day/night state
int posit = 0; // command for h-bridge
int state = 0;  // 0=partial, 1=open, 2=closed, 3=missing


void setup()
{
  Serial.begin(9600);  //Begin serial communcation
  pinMode(lightPin, INPUT);
  pinMode(topPin, INPUT);
  pinMode(botPin, INPUT);

}

void loop()
{

int topState, botState, lightread;  // variables to hold the pushbutton states
  topState = digitalRead(topPin);
  botState = digitalRead(botPin);
  lightread = analogRead(lightPin);
  Serial.println(analogRead(lightPin));

if (lightread >= threshold) // then it is dark
  {int dark = 1;
   Serial.print("its night");}
  else {int dark = 0;
     Serial.print("its day");
  }
 Serial.println(); // carriage return
       
 if ((topState == HIGH) && (botState == HIGH))
 {int state = 0;
 Serial.print("partial");} 
 else if ((topState == HIGH) && (botState == LOW)) 
 {int state = 1;
  Serial.print("open");} 
  else if ((topState == LOW) && (botState == HIGH))
 {int state = 2;
  Serial.print("closed");}
  else if ((topPin == LOW) && (botPin == LOW))
{int state = 3;
 Serial.print("no door!");
 }
 
 Serial.println(); // carriage return

if ((closed == 1) && (dark == 1))
{int posit = 1;
 Serial.print("halt closed");
 }
 else if ((opened == 1) && (dark == 0))
 {int posit = 1;
  Serial.print("halt open");
}
  else if ((closed == 1) && (dark == 0))
 {int posit = 2;
  Serial.print("door up");
}
  else if ((opened == 1) && (dark == 1))
 {int posit = 3;
  Serial.print("door down");
} 
  else if ((state == 0) && (dark == 0))
 {int posit = 3;
  Serial.print("all variables set to zero but why?!");
} 
 Serial.println(); // carriage return

   delay (1000);

};

The Problem:
The "sensors" both seem to work; i can put my hand over the photoresistor and the serial monitor will confirm that it thinks it's night. I can depress a limit switch and the program will believe the door is open or closed. The trouble comes when i want to combine the input from the photoresistor and the door state to give a command to the motor.

Below is a selection of responses from the serial monitor.
The first line is the analogread from the photoresistor
The second line states day/night
The third line states door limit switch state
And the fourth line should print the desired motor command for the H-Bridge; however I only ever seem to get one response

What i've determined is the motor command if-then-else function only seems to read the initial states of the variables (all zero).

414
its day
partial
all variables set to zero but why?!

713
its night
partial
all variables set to zero but why?!

530
its day
open
all variables set to zero but why?!

765
its night
closed
all variables set to zero but why?!

The criteria for "all variables set to zero but why?!" is

if ((state == 0) && (dark == 0))

aka partially open door (neither limit switch depressed) AND daytime

765
its night
closed
all variables set to zero but why?!

The above segment from the serial monitor seems to contradict itself which should mean that the variable change commands in the time of day and door state if-then-else functions are not changing the variables as i would expect them to.

I've tried not setting the state/dark variables to zero in the very first part of the code only to get the same results.

Short version: Despite getting serial monitor readouts confirming what the sensors should read, the variables that store the sensor states are not updating.

if ((closed == 1) && (dark == 1))
{int posit = 1;
 Serial.print("halt closed");
 }

You need to read about variable scope.
In the meantime, lose the "int" in front of "posit"

Thanks AWOL, got rid of all of the int’s in the if-then-else function and it works just how i would expect it to!

you’ve done a great service to my chickens thanks you!