This is my first Chielf Delphi post so thank you for your patience!
I want to run another command while I press button 3 on my controller. I would like to toggle between running and not running the command, so I found .whiletrue on the WPILIB.
// While holding the shoulder button, drive at half speed
new JoystickButton(m_driverController, Button.kRightBumper.value)
.whileTrue(new HalveDriveSpeed(m_robotDrive));
I used this to create:
new JoystickButton(driverJoytick, 1).whileTrue(new otherCommand(swerveSubsystem));
However, the .whiletTrue gives an error and says
The method whileTrue(otherCommand) is undefined for the type JoystickButtonJava(67108964)
I’m confused what “Button.kRightBumper.value” could refer to. On the page, it used
Trigger yButton = new JoystickButton(exampleController, XboxController.Button.kY.value);
I agree with the above. Probably an issue with that you are passing as your command.
You are doing that correctly already. If you look at the Documentation for the JoystickButton constructor it takes a GenericHID object (a joystick object) and an int for the button number.
The Button.kRightBumper.value and XboxController.Button.kY.value are just integers wrapped in other classes and variables so you can reference the name of the button for common controllers rather than having to look up the numbers for the “X” or “Y” Buttons.
You are using the 2023 WPILib, correct? whileActiveOnce is the old method, and while it still exists in the 2023 WPILib, it is deprecated and replaced by whileTrue. So if you’re using the 2022 WPIlib still, you won’t have whileTrue.