Skip to main content

Conditions

A condition is a test that answers true or false. Apoli uses conditions to ask about the world, for example whether the entity is sneaking, whether it is raining or whether its health is below half. Powers use them to switch on and off, meta-actions branch on them, and actions use them to filter targets.

The shape of a condition

A condition is a typed object like everything else:

{ "type": "apoli:sneaking" }

A condition only reports a result. Whatever checks it decides what to do with the answer.

Where conditions are used

  • A power's shared condition field makes the power active only while the test passes.
  • apoli:if_else and the other branching meta-actions pick an action based on a condition.
  • Many action powers, like apoli:action_on_hit, take a condition that must hold before the action fires.
  • Meta-conditions combine several conditions into one.

Kinds of condition

Like actions, conditions have kinds based on what they test:

KindTestsExamples
Entityone entityapoli:sneaking, apoli:health
Bi-entitya pair of entitiesapoli:attacker, apoli:undirected
Blocka blockapoli:block_state, apoli:in_tag
Iteman item stackapoli:enchantment, apoli:food
Damagea damage sourceapoli:type, apoli:amount
Biomea biomeapoli:temperature, apoli:precipitation
Fluida fluid stateapoli:still, apoli:empty
Metaother conditionsapoli:all_of, apoli:any_of

Inverting

Add "inverted": true to flip any condition. There is no not_sneaking condition, so you invert sneaking:

{ "type": "apoli:sneaking", "inverted": true }

Combining conditions

To test several things at once, wrap them in a meta-condition:

{
  "type": "apoli:and",
  "conditions": [
    { "type": "apoli:sneaking" },
    { "type": "apoli:on_fire", "inverted": true }
  ]
}
Meta-conditionPasses when
apoli:and or apoli:all_ofevery listed condition passes
apoli:or or apoli:any_ofany listed condition passes
apoli:constantalways returns the value you give it (true or false)

Meta-conditions nest, so an apoli:or of two apoli:and conditions works.

Next