Denizen Script Commands


Commands are always written with a '-' before them, and are the core component of any script, the primary way to cause things to happen.
Learn about how commands work in The Beginner's Guide.


Showing 1 out of 174 commands...
NameIf
Related Guide Pagehttps://guide.denizenscript.com/guides/basics/if-command.html
Syntaxif [<value>] (!)(<operator> <value>) (&&/|| ...) [<commands>]
Short DescriptionCompares values, and runs a subset of commands if they match.
Full DescriptionCompares values, and runs a subset of commands if they match.
Works with the else command, which handles alternatives for when the comparison fails.
The if command is equivalent to the English phrasing "if something is true, then do the following".

Values are compared using the comparable system. See Language:operator for information.

Comparisons may be chained together using the symbols '&&' and '||' or their text equivalents 'and' and 'or'.
'&&' means "and", '||' means "or".
So, for example "if <[a]> && <[b]>:" requires both a AND b to be true.
"if <[a]> and <[b]>:" also requires both a AND b to be true.

The "or" is inclusive, meaning "if <[a]> || <[b]>:" will pass for any of the following:
a = true, b = true
a = true, b = false
a = false, b = true
but will fail when a = false and b = false.

Sets of comparisons may be grouped using ( parens ) as separate arguments.
So, for example "if ( <[a]> && <[b]> ) || <[c]>", or "if ( <[x]> or <[y]> or <[z]> ) and ( <[a]> or <[b]> or <[c]> )"
Grouping is REQUIRED when using both '&&' and '||' in one line. Otherwise, groupings should not be used at all.

Boolean inputs and groups both support negating with the '!' symbol as a prefix.
This means you can do "if !<[a]>" to say "if a is NOT true".
Similarly, you can do "if !( <[a]> || <[b]> )", though be aware that per rules of boolean logic,
that example is the exactly same as "if !<[a]> && !<[b]>".

You can also use keyword "not" as its own argument to negate a boolean or an operator.
For example, "if not <[a]>:" will require a to be false, and "if <[a]> not equals <[b]>:" will require that 'a' does not equal 'b'.
Related Tags<ObjectTag.is[<operator>].to[<element>]> Takes an operator, and compares the first object to the given second object. (...)
<ObjectTag.is[<operator>].than[<element>]> Takes an operator, and compares the first object to the given second object. (...)
Usage Example
#Use to narrate a message only if a player has a flag.
- if <player.has_flag[secrets]>:
    - narrate "The secret number is 3!"
Usage Example
#Use to narrate a different message depending on a player's money level.
- if <player.money> > 1000:
    - narrate "You're rich!"
- else:
    - narrate "You're poor!"
Usage Example
#Use to stop a script if a player doesn't have all the prerequisites.
- if !<player.has_flag[quest_complete]> || !<player.has_permission[new_quests]> || <player.money> < 50:
    - narrate "You're not ready!"
    - stop
- narrate "Okay so your quest is to find the needle item in the haystack build next to town."
Usage Example
#Use to perform a complicated requirements test before before changing some event.
- if ( poison|magic|melting contains <context.cause> and <context.damage> > 5 ) or <player.has_flag[weak]>:
    - determine <context.damage.mul[2]>
Groupqueue
Sourcehttps://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/queue/IfCommand.java#L28