variables and operations help

I am trying to program a remote control to provide variable speed to our shooter system. When 7U is pressed the variable should increase by +10, instead it immediately jumps to +127. When 7D is pressed the variable should decrease by -10 but instead jumps to -127. I don’t understand why based on the math operations I’m using.

I’ve looked through the operations section of help and have not found anything that explains it. Please see the attached code.

ROBOTC and the cortex will process the statements of your code very fast. A while loop without any delays will perform perhaps 100000 loops every second. In the code posted you have a while loop that checks for button presses, when you detect the press you correctly increment or decrement a value, but this happens every time around the while loop, not just once, so the shooter speed will change very fast. A modified version of the code may be as follows.

#pragma config(Motor,  port1,           shooter,       tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  int  shooter_speed = 0;
  bool button_pressed = false;
  
  while(1)
    {
    motor shooter ] = shooter_speed;
    
    // Detect button press
    if( vexRT Btn7U ] == 1 && !button_pressed )
        {
        shooter_speed += 10;
        button_pressed = true;
        }
    else 
    if( vexRT Btn7D ] == 1 && !button_pressed )
        {
        shooter_speed -= 10;
        button_pressed = true;
        }
    else
    if( vexRT Btn7U ] == 0 && vexRT Btn7D ] == 0 )
        button_pressed = false;
      
    // Clip to the range 0 ~ 120
    if( shooter_speed > 120 ) shooter_speed = 120;
    if( shooter_speed <   0 ) shooter_speed = 0;
    
    // No need to run super fast
    wait1Msec(25);
    }
}

You probably also want to limit the variable as I did in the example.