Template:Plus if pos: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
m (Taylan moved page Template:Plus if positive to Template:Plus if pos without leaving a redirect)
(Accept mathematical expressions.)
Line 1: Line 1:
<includeonly>{{#ifexpr: {{{1}}} > 0 | + }}{{trim | {{{1}}} }}</includeonly><noinclude>
<includeonly>{{#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 positive | 5 }}
{{plus if pos | 2 + 3 }}
</pre>
</pre>


Result:
Result:


{{plus if positive | 5 }}
{{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 positive | {{#expr: floor({{#lvar:dex}} / 2) - 5 }} }} }}
{{#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 positive | {{#expr: floor({{#lvar:dex}} / 2) - 5 }} }} }}
{{#lvardef: dex_mod | {{plus if pos | floor({{#lvar:dex}} / 2) - 5 }} }}


}}
}}

Revision as of 17:12, 7 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.)