I went through the code more closely than last time...
JoystickButton inherits whileHeld from
Button.
Button extends
Trigger.
whileHeld calls Trigger's
whileActive method
From Javadoc:
Code:
whileActive
public void whileActive(Command command)
Constantly starts the given command while the button is held. Command.start() will be called repeatedly while the trigger is active, and will be canceled when the trigger becomes inactive.
Parameters:
command - the command to start
That's as far as I went. I assumed that calling start repeatedly on a command would cause it to cancel a previous running instance of the command. What it does do:
Command.start() adds the command to a vector of command that should be added to the list of commands that the scheduler will process.
Here's the catch, the scheduler doesn't do anything with the command if the command is already in the list. See
line 145.
So I agree. whileHeld should work as advertised. I know that I've had trouble with it in the past, and have always implemented commands as I outlined above. Maybe the problems I had with whileHeld were actually with something else, I haven't gone back to investigate.