Template:Plus if pos: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(Tolerate empty argument (return empty string).) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly>{{#ifexpr: {{{1}}} > 0 | + }}{{ | <includeonly>{{#if: {{{1|}}} | {{#ifexpr: {{{1}}} > 0 | + }}{{#expr: {{{1}}} }} }}</includeonly><noinclude> | ||
Adds a plus sign in front of a number if it's positive. Example: | Adds a plus sign in front of a number if it's positive. Also accepts mathematical expressions. Example: | ||
<pre> | <pre> | ||
{{plus if | {{plus if pos | 2 + 3 }} | ||
</pre> | </pre> | ||
Result: | Result: | ||
{{plus if | {{plus if pos | 5 }} | ||
This is useful when calculating some modifier. For example: | This is useful when calculating some modifier. For example: | ||
Line 16: | Line 16: | ||
{{#lvardef: dex | 14 }} | {{#lvardef: dex | 14 }} | ||
{{#lvardef: dex_mod | {{plus if | {{#lvardef: dex_mod | {{plus if pos | floor({{#lvar:dex}} / 2) - 5 }} }} | ||
}} | }} | ||
Line 28: | Line 28: | ||
{{#lvardef: dex | 14 }} | {{#lvardef: dex | 14 }} | ||
{{#lvardef: dex_mod | {{plus if | {{#lvardef: dex_mod | {{plus if pos | floor({{#lvar:dex}} / 2) - 5 }} }} | ||
}} | }} |
Latest revision as of 23:10, 10 June 2024
Adds a plus sign in front of a number if it's positive. Also accepts mathematical expressions. Example:
{{plus if pos | 2 + 3 }}
Result:
+5
This is useful when calculating some modifier. For example:
{{hidden code| {{#lvardef: dex | 14 }} {{#lvardef: dex_mod | {{plus if pos | floor({{#lvar:dex}} / 2) - 5 }} }} }} Your Dexterity Modifier is: {{#lvar:dex_mod}}
Result:
Your Dexterity Modifier is: +2
(Note: Don't be confused by use of Template:Hidden code in the example; it's an unrelated trick for using variable definitions without causing empty paragraphs.)