How to use joystick button to activate talon?

public class Robot {
private Spark motorFrontLeft = new Spark (0);
private Spark motorRearLeft = new Spark (2);
private Spark motorFrontRight = new Spark (1);
private Spark motorRearRight = new Spark (3);
** private Spark motorTilt = new Spark (4);**

private SpeedControllerGroup motorLeft = new SpeedControllerGroup (motorFrontLeft, motorRearLeft);
private SpeedControllerGroup motorRight = new SpeedControllerGroup (motorFrontRight, motorRearRight);
private DifferentialDrive driveTrain = new DifferentialDrive (motorLeft, motorRight);

private static final Joystick joystick = new Joystick (0);

public Robot () {

  driveTrain.setExpiration (0.1);

}
public void robotInit () {}

public void teleopPeriodic () {

 driveTrain.arcadeDrive (0.5 * joystick.getY(), 0.5 * joystick.getX());

**if (joystick.getTrigger()==true) {

     motorTilt.set (-0.3);

 } else if (joystick.getTop()==true){

     motorTilt.set(0.3);

 }else {

     motorTilt.set(0);

 }     **

}
public void test () {}
}

Is the code theoretically alright?

Presuming that you want the “tilt” motor only to be active WHILE you are holding the respective buttons down, I don’t see anything amiss. When neither control is active, the tilt motor will be off, which will “Put Sir Isaac Newton in the driver’s seat” - inertia and friction and gravity will rule, plus motor braking if Spark 4 is in brake mode.