quick programming question

hi all, newbie to arduino here, anyway im working on a project involving a nano, 2 dc motors controlled with joysticks, and a servo controlled by push buttons. I have a L298n controlling the 2 dc motors. anyway the problem im having is with the coding, iv managed to get the coding for the motors to work in 1 sketch and the servo in another sketch i just cant seem to add them both together to make them all work off 1 nano. heres the code for the servo controlled by push buttons

#include<Servo.h>
int pos = 0;

Servo servo;
void setup() {
  pinMode(2, INPUT);
  pinMode(11, INPUT);
  servo.attach(10);
}
void loop() {
  if (digitalRead(2) == HIGH && pos < 180) {
    pos++;
    servo.write(pos);
    delay(10);
  }
  if (digitalRead(11) == HIGH && pos > 0) {
    pos--;
    servo.write(pos);
    delay(10);
  }
}

and heres the code for the motors via L298n H bridge controlled with joysticks

// Motor A
 
int enA = 9;
int in1 = 8;
int in2 = 7;
 
// Motor B
 
int enB = 3;
int in3 = 5;
int in4 = 4;
 
// Joystick Input
 
int joyVert = A0; // Vertical  
int joyHorz = A1; // Horizontal
 
// Motor Speed Values - Start at zero
 
int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
 
// Joystick Values - Start at 512 (middle position)
 
int joyposVert = 512;
int joyposHorz = 512;  
 
 
void setup()
 
{
 
  // Set all the motor control pins to outputs
 
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
   
  // Start with motors disabled and direction forward
  
  // Motor A
  
  digitalWrite(enA, LOW);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  
  // Motor B
  
  digitalWrite(enB, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  
}
 
void loop() {
 
  // Read the Joystick X and Y positions
 
  joyposVert = analogRead(joyVert); 
  joyposHorz = analogRead(joyHorz);
 
  // Determine if this is a forward or backward motion
  // Do this by reading the Verticle Value
  // Apply results to MotorSpeed and to Direction
 
  if (joyposVert < 460)
  {
    // This is Backward
 
    // Set Motor A backward
 
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
 
    //Determine Motor Speeds
 
    // As we are going backwards we need to reverse readings
 
    joyposVert = joyposVert - 460; // This produces a negative number
    joyposVert = joyposVert * -1;  // Make the number positive
 
    MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
 
  }
  else if (joyposVert > 564)
  {
    // This is Forward
 
    // Set Motor A forward
 
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
 
    //Determine Motor Speeds
 
    MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
 
  }
  else
  {
    // This is Stopped
 
    MotorSpeed1 = 0;
 
  }
if (joyposHorz < 460)
  {
    // This is Backward
 
    // Set Motor B backward
 
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
 
    //Determine Motor Speeds
 
    // As we are going backwards we need to reverse readings
 
    joyposHorz = joyposHorz - 460; // This produces a negative number
    joyposHorz = joyposHorz * -1;  // Make the number positive
 
    MotorSpeed2 = map(joyposHorz, 0, 460, 0, 255);
 
  }
  else if (joyposHorz > 564)
  {
    // This is Forward
 
    // Set Motor B forward
 
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
 
    //Determine Motor Speeds
 
    MotorSpeed2 = map(joyposHorz, 564, 1023, 0, 255); 
 
  }
  else
  {
    // This is Stopped
 
    MotorSpeed2 = 0; 
 
  }
  // Adjust to prevent "buzzing" at very low speed
 
  if (MotorSpeed1 < 8)MotorSpeed1 = 0;
  if (MotorSpeed2 < 8)MotorSpeed2 = 0;
 
  // Set the motor speeds
 
  analogWrite(enA, MotorSpeed1);
  analogWrite(enB, MotorSpeed2);
 
}

if anyone is able to help me merge these to sketches to work together it would be much appreciated.

(deleted)

thanks spycatcher, that code works good when im not using the joysticks and just the push buttons for the servo that works good. but when i use the joysticks to control the motors the servo moves, (anyone know why this is??)

i notice you put the servo part first in the loop where as ive always added it to the bottom, cheers for the help

How are the switches wired? I bet you're not using the internal pullups and your switch is wired to +5V only. When the switch isn't pressed, that's a floating input. Small amounts of interference (like a motor moving) will trigger the switch states.

Give the switches names. Don't just use the bare "2" and "11" to refer to them.

"in1" "in2" "in3" "in4" are poor names for output pins. Unless this is the name of the pin written on the motor-control board, pick a more descriptive name. Names are free. There's no cost for using a long name. this_is_the_pin_that_moves_my_door_motor_forwards is actually a pretty good name for a pin.

damn your right, runs good now, also anyone know what numbers to change to adjust the max speed i need to slow the dc motors down abit

Whichever of the "in" pins is on a PWM pin on your particular Arduino can use analogWrite() to set the motor speed slower.