Conditions

In our scripting language, conditions provide a way to filter and refine the behavior of your triggers. While triggers initiate a set of actions based on specific events, conditions allow you to define additional criteria that must be met for those actions to execute.

For example, suppose you want to create a script that sends a message to the player every second, but only if the player is sneaking and in creative mode. By combining the onTick trigger with conditions, you can ensure that the message is only sent under those specific circumstances.

sneak-message:
  trigger: "onTick:20"  # This will activate every second
  conditions:
    - 'player.sneaking?'  # Check if the player is sneaking
    - 'player.gamemode == :CREATIVE'  # Check if the player is in creative mode
  actions:
    - 'player.send_message("You are sneaking in creative mode!")'

This can help you create more tailored interactions and avoid unnecessary actions when certain criteria are not met. Conditions give you the flexibility to design complex behaviors in your scripts, enhancing the overall functionality and responsiveness of your game.

You can think of conditions as "if statements" that determine whether the actions associated with a trigger should be carried out, making your scripts more dynamic and engaging.

What is Considered a Condition?

In our scripting language, a condition is anything that evaluates to a Boolean value—either true or false. This could be a variable or a function that checks a certain state or property. If the result of the condition is true, the actions tied to the trigger will be executed. If the result is false, the actions will be skipped.

For example, the Spigot API provides many methods that return Boolean values. A common one is player.sneaking?, which checks if a player is sneaking. This function returns true if the player is sneaking and false if not.

Here's another example:

# This script sends a message if the player is flying and has less than 5 hearts

flying-low-health:
  trigger: "onTick:20"  # Activates every second
  conditions:
    - 'player.flying?'  # Checks if the player is flying
    - 'player.health < 5'  # Checks if the player has less than 5 health points
  actions:
    - 'player.send_message("You are flying and have low health!")'

Last updated