Bindings are how you attach commands to user inputs or other events.

Mercurial uses the BoundBooleanSupplier system to provide bindings, which is a thin wrapper over EnhancedBooleanSupplier. Go read its documentation for more information.

Go look at gamepads for more information on the first line of these examples.

// we can set up commands to be run
Mercurial.gamepad1().a()
	// runs on the rising edge of button a
	.onTrue(new Lambda("command-name"))
	// runs on the falling edge of button a
	.onFalse(new Lambda("command-name"))
	// runs on the rising edge of button a, until the falling edge, then ends naturally
	.whileTrue(new Lambda("command-name"))
	// runs on the falling edge of button a, until the rising edge, then ends naturally
	.whileFalse(new Lambda("command-name"))
	// runs on the rising edge of button a, reschedules if it ends early, until the falling edge, then ends naturally
	.untilFalse(new Lambda("command-name"))
	// runs on the falling edge of button a, reschedules if it ends early, until the rising edge, then ends naturally
	.untilTrue(new Lambda("command-name"))
	// runs on the rising edge of button a, cancels on the next rising edge
	.toggleTrue(new Lambda("command-name"))
	// runs on the falling edge of button a, cancels on the next falling edge
	.toggleFalse(new Lambda("command-name"))
	// cancels on the rising edge of a
	.cancelOnTrue(new Lambda("command-name"))
	// cancels on the falling edge of a
	.cancelOnFalse(new Lambda("command-name"));

A BoundBooleanSupplier can be easily built from a BoundDoubleSupplier which is a thin wrapper over EnhancedDoubleSupplier. This is done by using the same conditional system built into EnhancedDoubleSuppliers.

The Mercurial gamepads use these for sticks and triggers.

Both of these classes can be easily constructed:

new BoundBooleanSupplier(() -> true);
// you can also wrap an EnhancedBooleanSupplier
new BoundBooleanSupplier(Pasteurized.gamepad1().a());
new BoundDoubleSupplier(() -> 0.0);
// you can also wrap an EnhancedDoubleSupplier
new BoundDoubleSupplier(Pasteurized.gamepad1().leftStickY());

// conditional binding
new BoundDoubleSupplier(() -> 0.0)
	.conditionalBindState()
	.greaterThan(10.0)
	.bind()
	.whileTrue(new Lambda("while-greater-than-10"));

Cool! Bindings is pretty easy, consider building bindings to events both internal and external to your system, like changes in internal state, or changes in sensor values, to perform a larger amount of automation when it comes to commands.