Model mountain gondola

Hi, sorry yet another newbee in trouble.

This program is an attempt at getting two gondolas (one each side) to go up a mountain and stop when being detected by a sensor. There is then supposed to be a delay before going back down again until the second gondola is detected.
The gondolas are physically arranged on opposite sides so that when one has reached the top, the other one is at the bottom.
The motor is being powered via a L293D shield to protect the Arduino Uno R3.

The motor isn't changing direction, so I guess the if loops aren't functioning and also it isn't stopping when I operate the end of travel by links to check function before fitting the actual sensors.

Realising that the sensors will lose their signal as the gondola moves away from them I have attempted to use lastState to remember until the sensor at the end of travel tells it to stop.

Any help would be much appreciated but please remember that I'm fairly new at this being a model train guy trying to make things more interesting for my grandchildren, so treat an old man gently please.

// 2 gondola model mountain cable car with 2 end travel sensors
// By Ken Nippard 31/9/19 try 2

// Allocate pin usage
int pwm = 3; // motor speed output signal
int Pd1 = 4; // cw limit of travel sensor
int Pd2 = 7; // ccw limit of travel sensor
int cw = 8; // cw motor direction signal
int ccw = 12; // ccw motor direction signal

// variable to save last sensor position
int lastPd1State;
int lastPd2State;

void setup()
{

pinMode (pwm, OUTPUT); // motor speed 0 - 255
pinMode (Pd1, INPUT_PULLUP));
pinMode (Pd2, INPUT_PULLUP);
pinMode (cw, OUTPUT); // motor direction
pinMode (ccw, OUTPUT); // motor direction
digitalWrite(Pd1, HIGH); // sensors go low on detect
digitalWrite(Pd2, HIGH);

} // end of setup

void loop()
{
lastPd1State == digitalRead (Pd1); // Check current sensor reading
lastPd2State == digitalRead (Pd2);
delay (2000);
if (lastPd1State == LOW) { // need to move in anticlockwise direction
digitalWrite (cw, LOW);
digitalWrite (ccw, HIGH);
analogWrite (pwm, 160);
while (digitalRead (lastPd2State) == HIGH); // not yet at end of travel
digitalWrite (ccw, LOW); //stop motor
delay (120000);
}

else if (lastPd2State == LOW) { // need to move in clockwise direction
digitalWrite (cw, HIGH);
digitalWrite (ccw, LOW);
analogWrite (pwm, 160);
while (digitalRead (lastPd1State) == HIGH);
digitalWrite (cw, LOW); //stop motor
delay (120000);
}
else { // starting with gondolas in mid position
digitalWrite (cw, HIGH);
digitalWrite (ccw, LOW);
analogWrite (pwm,160);
while (digitalRead (lastPd2State) == HIGH); // not yet at end of travel
digitalWrite (cw, LOW); // stop motor
delay (120000);

}
}

Please edit your post and insert code tags!

Any help would be much appreciated but please remember that I'm fairly new at this being a model train guy trying to make things more interesting for my grandchildren, so treat an old man gently please.

What exactly is the problem? I guess this code does not what you expect it to do. We have a slight clue what it should do but we don't know what it actually does wrong. Provide more information.

I would try to eliminate the delay() call in your code. Take a look at the example BlinkWithoutDelay to get some hints how to do that.

The motor isn't changing direction, so I guess the if loops aren't functioning and also it isn't stopping when I operate the end of travel (by links) to check function before fitting the actual sensors.

The motor is supposed to stop when one of the gondolas reaches the destination, then there is a delay before changing direction so that the gondola returns to the start position, so the fact the Arduino is waiting doesn't matter in my particular case.

Try turning up the warning level in the IDE preferences. I have it set to "All" and it produces a couple of very enlightening errors:

Users/martin/Documents/Arduino/test/test.ino: In function 'void loop()':
/Users/martin/Documents/Arduino/test/test.ino:28:16: warning: value computed is not used [-Wunused-value]
   lastPd1State == digitalRead (Pd1); // Check current sensor reading
                ^
/Users/martin/Documents/Arduino/test/test.ino:29:16: warning: value computed is not used [-Wunused-value]
   lastPd2State == digitalRead (Pd2);
                ^

You have made one of the classic errors that bites every newcomer to C++.
= is for assignment
== is for comparison.

You also have a superfluous closing bracket on line 18, so as posted, your code won't actually compile.