You have to set something else, cause this instruction is telling the programm to set the motor speed to x and because after that, there is nothing else to do, it is going to end the programm, faster then it is able to turn on the motors.
In order for it to do something, you have to make it do something else.
e.g. idle
wait1Msec(100);
You could also put it into a while loop
eather
while(true){motor[desiredMotor] = desiredSpeed;}
or you can do something like this
while(SensorValue[light]> 50) {motor[desiredMotor] = desiredSpeed;}
or
motor[desiredMotor] = desiredSpeed;
waituntil(SensorValue[light]> 50)
motor[desiredMotor] = 0;
you are welcome to use this function I found and edited to move a fixed distance
const float WHEEL_DIAMETER = 55; //diameter of the wheel in mm.
const float DISTANCE_BETWEEN_WHEELS = 140;//distance between wheels in mm.
const float ENCODER_RESOLUTION = 360; //the encoder's resolution.
const float MOVEMENT_FACTOR =((WHEEL_DIAMETER * PI) / ENCODER_RESOLUTION);
// for using just red motor speeds do (red motor value * MOVEMENT_FACTOR )
void drive2distance(int FLEngineSpeed, int FREngineSpeed,int FLEmm, int FREmm)
{
// set distance
nMotorEncoderTarget[FLEngine] = FLEmm / MOVEMENT_FACTOR;
nMotorEncoderTarget[FREngine] = FREmm / MOVEMENT_FACTOR;
//straight
motor[FLEngine] = FLEngineSpeed;
motor[FREngine] = FREngineSpeed;
while (nMotorRunState[FLEngine] != runStateIdle || nMotorRunState[FREngine] != runStateIdle) {}
//stop
motor[FLEngine] = 0;
motor[FREngine] = 0;
}