Firing Mechanism coding

I’m working on coding a firing mechanism and I am running into some issues. I need to have a motor (called Fire in the program) turn 30 degrees, or 30 tics on the encoder (called Encoder in the program) it is attached to at 30 power, wait 500 ms for the ball to roll out, then turn backwards the same number of tics at the same speed. I thought of doing while loops of if else statements, but all of them ended with the motor going back to 30 power as soon as the motor started to turn backwards. Any help would be appreciated. Thanks

Try


SensorValue[Encoder] = 0; // clear encoder

while(SensorValue[Encoder] < 30){ // while the motors have moved less than 30 degrees
     motor[Fire] = 30; // move motor at 30 power
}
motor[Fire] = 0; // turn off motor
wait1msec(500); // wait 500 mlsec
SensorValue[Encoder] = 0; // clear encoder

while(SensorValue[Encoder] > -30){ // while motors have moved less than -30 degrees
     motor[Fire] = -30; // move motor at -30 power
}

motor[Fire] = 0; // turn off motor

That’s pretty similar to stuff I have tried but it looks like it will work thanks!