Table of Contents
Comparisons
Comparison functions test one variable against either an integer literal or another variable. They return a boolean function result and also update the stdout: boolean helpers.
function var:comp/eq { k: "score", v: 10 }
execute if function stdout:true run say score is 10
Functions
| Function | Test |
|---|---|
var:comp/eq |
k == v |
var:comp/gt |
k > v |
var:comp/gteq |
k >= v |
var:comp/lt |
k < v |
var:comp/lteq |
k <= v |
Each function accepts:
| Argument | Type | Description |
|---|---|---|
k |
string | Variable name to test |
v |
int or string | Integer literal or another variable name |
Branching
The most reliable branch pattern is to run the comparison first, then branch with stdout:true or stdout:false.
function var:comp/gteq { k: "coins", v: 100 }
execute if function stdout:true run say enough coins
execute if function stdout:false run say not enough coins
Reusing the result
Since the result remains in mcfstd's boolean register until another boolean function overwrites it, you can branch several times after one comparison.
function var:comp/lt { k: "health", v: 1 }
execute if function stdout:true run say player is down
execute if function stdout:false run say player is still standing
Variable operands
If v names an existing variable, the comparison uses that variable's value.
function var:set { k: "current_wave", v: 4 }
function var:set { k: "final_wave", v: 5 }
function var:comp/lt { k: "current_wave", v: "final_wave" }
execute if function stdout:true run say more waves remain
If v is not an existing variable, mcfstd treats it as an integer literal.
Result state
Comparison functions write their result to the internal boolean register _std_a in _reg.
| Result | Register state | stdout:true |
stdout:false |
|---|---|---|---|
| true | _std_a = 1 |
returns true | returns false |
| false | _std_a = 0 |
returns false | returns true |
Calling another comparison or var:isset overwrites this state.