1), the first expression of code is the result, otherwise the second expression of code is the result.
This function doesn't have the parentheses limit that the roll option has:
[if(((1))): 1;0] <!-- in this case if() roll option fails --> [if(((1)),1,0)] <!-- in this case if() function works -->
if(condition, trueExpr, falseExpr)
condition- What is tested to determine is the
falseExprwill be executed. This follows the standard rules for conditions that can be found in the Branching and Looping article.
trueExpr- A section of code that is returned if
falseExpr- A section of code that is returned if
[h: a = 10] [h: b = 20] [r: if(a > b, "A is larger than B", "A is not larger than B")]
A is not larger than B
[h: number = 1] [r: if(number >= 1, 20, "")]
- Returns: A blank string, please note that a blank string is not an empty variable if you were to assign the output of this function.
[h: variable = "Foobar"] [r: if(variable == "Text", 1, 0)]
[h: variable = 20] [property = if(variable > 0 && variable < 20, 1, 0)]
Example 5: Usually its better to use the roll option version [if():]. Sometimes it's pretty handy to use the version documented here, since you can easily embed it in loops and expressions.
Let's say you want to check if one of a player's tokens has Initiative, you could do it this like this:
[h: tokensOfPlayer = getOwned(getPlayerName(), "json")] [h: hasIni = 0] [h: iniToken = getInitiativeToken()] [h, foreach(id, tokensOfPlayer): hasIni = if(id!=iniToken,hasIni,1)]