Skip to content

Conditionals

NextFTC has four conditional commands to help you implement conditional logic.

BlockingConditionalCommand

A BlockingConditionalCommand takes a condition, a command to run on true, and a command to run on false. The condition is a boolean supplier, which is evaluated when the command is scheduled. The BlockingConditionalCommand finishes when its inner command finishes.

kotlin
BlockingConditionalCommand(
    { 1 == 2 },
    { trueCommand },
    { falseCommand }
)

PassiveConditionalCommand

A PassiveConditionalCommand is similar to a BlockingConditionalCommand. However, instead of finishing when its inner command finishes, it schedules the inner command and finishes instantly.

kotlin
PassiveConditionalCommand(
    { 1 == 2 },
    { trueCommand },
    { falseCommand }
)

BlockingSwitchCommand

A BlockingSwitchCommand is like a BlockingConditionalCommand but for a switch statement.

kotlin
BlockingSwitchCommand(
    { "giraffe" },
    "beaver" to { beaverCommand },
    "giraffe" to { giraffeCommand },
    "hippo" to { hippoCommand }
)

In addition, you can optionally pass a default command:

kotlin
BlockingSwitchCommand(
    { "giraffe" },
    arrayOf(
        "beaver" to { beaverCommand },
        "giraffe" to { giraffeCommand },
        "hippo" to { hippoCommand }
    ),
    { defaultCommand }
)

PassiveSwitchCommand

A PassiveSwitchCommand is like a combination of a BlockingSwitchCommand and a PassiveConditionalCommand. It is a switch command that schedules the inner command and instantly finishes.

kotlin
PassiveSwitchCommand(
    { "giraffe" },
    "beaver" to { beaverCommand },
    "giraffe" to { giraffeCommand },
    "hippo" to { hippoCommand }
)

Just like with a BlockingSwitchCommand, you have the option to pass a default command:

kotlin
PassiveSwitchCommand(
    { "giraffe" },
    arrayOf(
        "beaver" to { beaverCommand },
        "giraffe" to { giraffeCommand },
        "hippo" to { hippoCommand }
    ),
    { defaultCommand }
)

NOTE

See the conditionals reference for more information.