if: Difference between revisions
Jump to navigation
Jump to search
Verisimilar (talk | contribs) (Added version, cleaned up formatting, removed condescending wording, moved generic condition text to Branching and Looping.) |
Verisimilar (talk | contribs) m (Typo correction.) |
||
Line 5: | Line 5: | ||
This function is used to check whether a certain code ''expression'' should be executed or not. If the ''condition'' to be evaluated with this function is {{code|true}}, the first ''expression'' of code is executed, otherwise the second ''expression'' of code is executed. | This function is used to check whether a certain code ''expression'' should be executed or not. If the ''condition'' to be evaluated with this function is {{code|true}}, the first ''expression'' of code is executed, otherwise the second ''expression'' of code is executed. | ||
'''Note:''' This function has been | '''Note:''' This function has been deprecated in favor of the [[if (roll option)|if (roll option)]]. Both {{code|trueExpr}} and {{code|falseExpr}} are evaluated regardless of what {{code|condition}} returns, so this should only be used in limited cases where a small ''branch'' is required within other functions. | ||
|usage= | |usage= |
Revision as of 02:41, 13 March 2009
if() Function
• Introduced in version 1.3b38
This function is used to check whether a certain code expression should be executed or not. If the condition to be evaluated with this function is
true
, the first expression of code is executed, otherwise the second expression of code is executed.
Note: This function has been deprecated in favor of the if (roll option). Both trueExpr
and falseExpr
are evaluated regardless of what condition
returns, so this should only be used in limited cases where a small branch is required within other functions.Usage
if(condition, trueExpr, falseExpr)
Parameters
condition
- What is tested to determine is thetrueExpr
orfalseExpr
will 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 executed ifcondition
returns astrue
.falseExpr
- A section of code that is executed ifcondition
does not return astrue
.
Examples
Example 1: If
Returns:
a
is 10
and b
is 20
:
[r: if(a > b, "A is larger than B", "A is not larger than B")]
Returns: A is not larger than B
Example 2: If number
is 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.
Example 3: If variable
is "Foobar"
:
[r: if(variable == "Text", 1, 0)]
Returns: 0
Example 4: If variable
is 20
[property = if(variable > 0 && variable < 20, 1, 0)]
property
set to 0