🚧
CustomHud v4 Docs are WIP
For temporary documentation on all the features added in v4, see the changelog
🚧

Conditionals

Conditionals allow you to change what is displayed depending on the result of some variables.

Syntax

There are two versions of conditionals, multi-line and in-line. Multi-Line allows you to optionally display entire sections of the config. This is good for stuff like showing what block you're looking at and its properties. In-Line acts like a variable in the sense that you can put it anywhere. This is useful for changing a line depending on something, or changing the color of something depending on its value.

Multi-Line

You can have multiple or zero elseif . else is also optional.

=if: cond_1=
if cond_1 is true
=elseif: cond_2=
if cond_1 is false but cond_2 is true
=else=
if all if/elseif conditions are false
=endif=

In-Line

You can chain as many cond, "if cond is true" as you want.
You can also put a conditional in a conditional one level deep by replacing the ' s instead of " s for the inner one

{{condition, "if condition is true"}}
{{condition, "if condition is true", "if condition is false"}}
{{cond_1, "if cond_1 is true", cond_2, "if cond_2 is true"}}
{{cond_1, "if cond_1 is true", cond_2, "if cond_2 is true", "if neither are true"}}

What do I put in the condition (or cond) spot?

Basically anything that produces a true / false value. There's two main ways to do this:

Notice the lack of {} s next to pitch and version. In the conditional section, you don't put {} s around variables.


Example 1: Nether Coordinates (In-Line)

{nx} and {nz} show the Nether equivalent coordinates when you're in the Overworld or end, but show the Overworld equivalent coordinates when you're in the Nether. What if you wanted the label to reflex that?

  • {{nether, "Overworld", "Nether"}}: {nx} {y} {nz}

Okay, let's break that down:

  • nether is a variable, that according to the Boolean Value column in the Variables page, is true if you're in the nether, and false otherwise.
  • "Overworld" will display if are in the nether
  • "Nether" will display if aren't in the nether
  • : {nx} {y} {nz} Since this isn't in the conditional, it will always display

If you only want to show the line if you're not in the nether, then you can do:

  • {{nether, "", "Nether: &a{nx} {y} {nz}"}}
  • Note: The true section is just an empty "". If this is the only thing on the line in the profile file, and you're not in the nether, then this line will be ignored instead of having a blank line

Example 2: Looking at Block (Multi-Line)

What if we want to show the property of the block that we're looking at?

=if: target_block=
&nLooking at: {tbx} {tby} {tbz}

{target_block}
&7&o{target_block_id}
=endif=

Okay, let's break that down:

  • target_block is a variable, that according to the Boolean Value column in the Variables page, is true if you're looking at a block.
  • {tbx} {tby} {tbz}" are the coordinates of the block you're looking at
  • {target_block} shows the block's name
  • {target_block_id} shows the block's id
  • &n underlines the line, &7 changes the color to grey, and &o italicizes the line (see the Color page)

Comparisons

As mentioned in the previous section, you can do comparisons like pitch > 0 or version = "1.16.2" , let's expand on that.

Variables can produce 3 values: String, Number, and Boolean. We already used the boolean value in Example 1.

Which value is used in the conditional depends on which operator you use, here's a list:

Operators

Symbol Name What It Compares
| Or Boolean Values
& And Boolean Values
< Less Than Number Values
> Greater Than Number Values
<= Less Than or Equal To Number Values
>= Greater Than or Equal To Number Values
= Equal It Depends*
!= Not Equal It Depends*

It Depends*

  • x = 5 will compare Number Values, because 5 is a number
  • nether = false will compare Boolean Values, because false is a boolean
  • version = "1.19.2" will compare String Values, because "1.19.2" is a string
  • client_version = modded_name will compare String Values, because both are variables

Grouping

If you're using multiple conditions in 1 conditional, and want group them to ensure the order, you can group them with () s.

Example: {{y > 60 & (z > 0 | x > 0), "Yes", "No"}}

Example 3: Colored FPS

What if we want to change the color of our fps depending on its value?

  • {{fps >= 60, "&a", fps >= 30, "&e", "&c"}}{fps} fps

Okay, let's break that down:

  • fps >= 60, "&a" checks if the fps is greater than or equal to 60
    • If so, it puts the green color code &a
  • fps >= 30, "&e" if the fps wasn't 60 or more, checks if the fps is above or equal to 30
    • If so, it puts the yellow color code &e
  • If the fps wasn't greater than or equal to 60 and fps wasn't greater or equal to 30,
    • If so, it puts the red color code &c
  • {fps} fps being outside the conditional, always shows. But now it shows in the color we want!