if: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Applied Template:MacroFunction)
Line 1: Line 1:
==Function if==
{{MacroFunction
|name=if
|description=
If ''testCondition'' evaluates to 0 then the result of ''falseExpr'' is returned, otherwise the result of ''trueExpr'' is returned. Note: '''both''' ''trueExpr'' and ''falseExpr'' are evaluated no matter what the result of ''testCondition'' is. You may want to consider using the [[Macros:Branching_and_Looping#IF_Option| [IF():]]] roll option instead.
If ''testCondition'' evaluates to 0 then the result of ''falseExpr'' is returned, otherwise the result of ''trueExpr'' is returned. Note: '''both''' ''trueExpr'' and ''falseExpr'' are evaluated no matter what the result of ''testCondition'' is. You may want to consider using the [[Macros:Branching_and_Looping#IF_Option| [IF():]]] roll option instead.


Line 12: Line 14:
If you are checking for a text string, place quotes around the text. You can find more information on these and other logical operations useful for the if function halfway down this page: http://rptools.net/doku.php?id=parser
If you are checking for a text string, place quotes around the text. You can find more information on these and other logical operations useful for the if function halfway down this page: http://rptools.net/doku.php?id=parser


===Usage===
|usage=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: result = if(testCondition, trueExpr, falseCondition)]
[h: result = if(testCondition, trueExpr, falseCondition)]
</source>
</source>


===Examples===
|examples=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[r: if(a>b, "A is larger than B", "A is not larger than B")]
[r: if(a>b, "A is larger than B", "A is not larger than B")]
Line 33: Line 35:
[someProperty = if(variable>0 && variable<20,1,0)]</source>
[someProperty = if(variable>0 && variable<20,1,0)]</source>
Sets ''someProperty'' to 1 if variable is between 0 and 20.
Sets ''someProperty'' to 1 if variable is between 0 and 20.
}}
[[Category:Miscellaneous Function]]

Revision as of 19:50, 8 March 2009

if() Function

If testCondition evaluates to 0 then the result of falseExpr is returned, otherwise the result of trueExpr is returned. Note: both trueExpr and falseExpr are evaluated no matter what the result of testCondition is. You may want to consider using the [IF():] roll option instead.

Test condition notation:

  • > for greater than
  • < for less than
  • >= for greater than or equal to
  • <= for less than or equal to
  • == for equal to - yes, you must use TWO equal signs to evaluate "is equal to"
If you are checking for a text string, place quotes around the text. You can find more information on these and other logical operations useful for the if function halfway down this page: http://rptools.net/doku.php?id=parser

Usage

[h: result = if(testCondition, trueExpr, falseCondition)]

Examples

[r: if(a>b, "A is larger than B", "A is not larger than B")]
[someProperty = if(variable>=1,20,"")]

Sets someProperty to 20 if variable is greater than or equal to 1, or makes it blank (but not empty) otherwise.

[someProperty = if(variable=="Text",1,0)]

Sets someProperty to 1 if variable contains the text string Text, 0 otherwise.

[someProperty = if(variable>0 && variable<20,1,0)]
Sets someProperty to 1 if variable is between 0 and 20.