Conditonals - Minenash/CustomHUD GitHub Wiki

The wiki has moved!
New Page: https://customhud.dev/v2/conditionals

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

The syntax is

  • {{conditional, "what to display if true"}} OR
  • {{conditional, "what to display if true", "what to display if false"}}

You can nest conditionals one deep, by using 's instead of "s

Empty lines caused by empty arguments get ignored. So any lines you manually put into the profile files, will stay, but if that's your only argument on a line, then you won't have an empty line

To see when a variable will produce true or false, check the Variable Reference, specifically the Bool column. But here are some general principles:

  • Variables that produce numbers: if the number is above 0
  • Variables that produce strings: if there is anything that would render
  • Variable that produce boolean: if the value it gives is true

Conditional Format:

Variables can produce 3 values:

  • A string value
  • A number value
  • A boolean value

When rendering the hud, the string value is used, but you can use the others to compare variables to other variables or variables to a literal.

Operators:

Symbol Name What it compares
| or boolean values
& and boolean values
< less than number values
> greaterthan number values
<= less than or equal number values
>= greater than or equal number values
= equals depends*
!= not equal depends*

depends*:

  • If one of the values being compared is a boolean (not variable): boolean values
  • If one of the values being compared is a number (not variable): number values
  • Else: string values

You can also group by ()s. Like {{y > 60 & (z > 0 | x > 0), "Yes", "No"}}

Example 1:

What if I wanted to show the nether equivalent coordinates, but when you're already in the nether {nx} and {nz} shows the overworld equivalent coordinates instead, but you want to show the correct label.

{{nether, "Overworld", "Nether"}}: &a{nx} {y} {nz}
  • nether - Is the player in the nether?
  • nx - Nether X equivalent
  • nz - Nether Z equivalent (the y coordinates are the same between the dimentions)

or maybe , you don't want to show the line at all when you're in the nether. You could do

{{nether, "", "Nether: &a{nx} {y} {nz}"}}

Example 2:

What if I wanted to change the color of the {fps} variable, depending on it's value.

{{fps >= 60, "&a"}}{{fps < 60 & fps >= 30, "&e"}}{{fps < 30, "&c"}}{fps} fps
  • The first conditional checks to see if the fps is greater than or equal to 60.
    • If so, it puts the green color code (&a)
  • The second conditional checks to see if the fps is less than 60 AND greater than or equal to 30
    • If so, it puts the yellow color code (&e)
  • The first conditional checks to see if the fps is less than 30.
    • If so, it puts the red color code (&c)
⚠️ **GitHub.com Fallback** ⚠️