Template:Plus if pos: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(Accept mathematical expressions.)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<includeonly>{{#ifexpr: {{{1}}} > 0 | + }}{{#expr: {{{1}}} }}</includeonly><noinclude>
<includeonly>{{#if: {{{1|}}} | {{#ifexpr: {{{1}}} > 0 | + }}{{#expr: {{{1}}} }} }}</includeonly><noinclude>{{Documentation|content=
Adds a plus sign in front of a number if it's positive. Also accepts mathematical expressions. Example:
Adds a plus sign in front of a number if it's positive. Also accepts mathematical expressions. Example:


Line 35: Line 35:


(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.)
(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.)
}}
[[Category:Templates]]
</noinclude>
</noinclude>

Latest revision as of 20:55, 19 January 2025

Template documentation

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.)