Work in progress — This wiki is an active migration / mirror of Homestar Runner Wiki and is not finished yet. Account registration and public editing are turned off until the migration is further along. For status updates, see the migration thread on the forums.

HRWiki Counter: Difference between revisions

From HR Wiki Twice
Jump to navigationJump to search
imported>HRWikiMirrorBot
Imported from hrwiki.org via Wayback Machine (HTML→wikitext)
 
imported>HRWikiMirrorBot
Reimported from hrwiki.org Wayback HTML→wikitext (full reconvert)
 
Line 1: Line 1:
<!-- Mirrored from Homestar Runner Wiki (hrwiki.org) via Wayback Machine; HTML converted to wikitext. Formatting may be imperfect. -->
<!-- Mirrored from Homestar Runner Wiki (hrwiki.org) via Wayback Machine -->
{| id="toc" class="wikitable toc" summary="Contents"
== Usage ==
|-
| <div id="toctitle">
 
<span id="contents"></span>
== Contents ==
 
</div>
* [#Usage 1 Usage]
* [#Examples 2 Examples]
* [#Sortable_Tables 3 Sortable Tables]
 
|}


<span id="usage"></span>
{| class="wikitable"
== <span class="mw-headline">Usage</span> ==
 
{| class="wikitable" border="1" style="border-collapse: collapse"
|-
|-
| <code>{{#count:</code>''id''<code>|</code>''increment''<code>}}</code>
| {{#count:''id''&#124;''increment''}}
| Increments the counter ''id'' by ''increment'' and displays the result; ''increment'' can be omitted, and defaults to <code>1</code>.
| Increments the counter ''id'' by ''increment'' and displays the result; ''increment'' can be omitted, and defaults to 1.
|-
|-
| <code>{{#resetcount:</code>''id''<code>|</code>''value''<code>|</code>''increment''<code>}}</code>
| {{#resetcount:''id''&#124;''value''&#124;''increment''}}
| Silently sets the counter ''id'' to ''value'' minus ''increment'' (so that the next count by ''increment'' will display ''value''); ''value'' and ''increment'' can be omitted, and both default to <code>1</code>.
| Silently sets the counter ''id'' to ''value'' minus ''increment'' (so that the next count by ''increment'' will display ''value''); ''value'' and ''increment'' can be omitted, and both default to 1.
|-
|-
| <code>{{[[Template:hcount|hcount]]}}</code><br />
| {{[[Template:hcount|hcount]]}}<br />{{[[Template:vcount|vcount]]}}
<code>{{[[Template:vcount|vcount]]}}</code>
| Used in [[HRWiki:SORT|sortable tables]]. ''See [#Sortable_Tables below].''
| Used in [[HRWiki:SORT|sortable tables]]. ''See [#Sortable_Tables below].''
|}
|}


<span id="examples"></span>
== Examples ==
== <span class="mw-headline">Examples</span> ==


'''count''' is a [[Help:Parser function|parser function]] that returns an integer that increments each time the function is called:
'''count''' is a [[Help:Parser function|parser function]] that returns an integer that increments each time the function is called:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 1
| 1
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 2
| 2
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 3
| 3
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 4
| 4
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 5
| 5
|}
|}


The counters can be given different names, so you can have more than one of them on the same page:<br />
The counters can be given different names, so you can have more than one of them on the same page:<br />
<span class="small">(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)</span>
(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#count:first}}</code>
| {{#count:first}}
| 1
| 1
|-
|-
| <code>{{#count:second}}</code>
| {{#count:second}}
| 1
| 1
|-
|-
| <code>{{#count:second}}</code>
| {{#count:second}}
| 2
| 2
|-
|-
| <code>{{#count:second}}</code>
| {{#count:second}}
| 3
| 3
|-
|-
| <code>{{#count:first}}</code>
| {{#count:first}}
| 2
| 2
|-
|-
| <code>{{#count:second}}</code>
| {{#count:second}}
| 4
| 4
|}
|}
Line 85: Line 68:
You can also make the counter count by twos, or by any other number:
You can also make the counter count by twos, or by any other number:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#count:evens|2}}</code>
| {{#count:evens&#124;2}}
| 2
| 2
|-
|-
| <code>{{#count:evens|2}}</code>
| {{#count:evens&#124;2}}
| 4
| 4
|-
|-
| <code>{{#count:evens|2}}</code>
| {{#count:evens&#124;2}}
| 6
| 6
|-
|-
| <code>{{#count:evens|2}}</code>
| {{#count:evens&#124;2}}
| 8
| 8
|-
|-
| <code>{{#count:evens|2}}</code>
| {{#count:evens&#124;2}}
| 10
| 10
|}
|}
Line 108: Line 91:
Different increments can be used at different times, depending on what is needed:
Different increments can be used at different times, depending on what is needed:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#count:strange|1}}</code>
| {{#count:strange&#124;1}}
| 1
| 1
|-
|-
| <code>{{#count:strange|1}}</code>
| {{#count:strange&#124;1}}
| 2
| 2
|-
|-
| <code>{{#count:strange|3}}</code>
| {{#count:strange&#124;3}}
| 5
| 5
|-
|-
| <code>{{#count:strange|0}}</code>
| {{#count:strange&#124;0}}
| 5
| 5
|-
|-
| <code>{{#count:strange|-1}}</code>
| {{#count:strange&#124;-1}}
| 4
| 4
|-
|-
| <code>{{#count:strange|2}}</code>
| {{#count:strange&#124;2}}
| 6
| 6
|}
|}
Line 134: Line 117:
The counter can be reset partway through a page:
The counter can be reset partway through a page:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 1
| 1
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 2
| 2
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 3
| 3
|-
|-
| <code>{{#resetcount:basic}}</code>
| {{#resetcount:basic}}
|
|  
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 1
| 1
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 2
| 2
|-
|-
| <code>{{#count:basic}}</code>
| {{#count:basic}}
| 3
| 3
|}
|}
Line 163: Line 146:
You can also set what number you want to start on:
You can also set what number you want to start on:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#resetcount:starting|11}}</code>
| {{#resetcount:starting&#124;11}}
|
|  
|-
|-
| <code>{{#count:starting}}</code>
| {{#count:starting}}
| 11
| 11
|-
|-
| <code>{{#count:starting}}</code>
| {{#count:starting}}
| 12
| 12
|-
|-
| <code>{{#count:starting}}</code>
| {{#count:starting}}
| 13
| 13
|-
|-
| <code>{{#count:starting}}</code>
| {{#count:starting}}
| 14
| 14
|-
|-
| <code>{{#count:starting}}</code>
| {{#count:starting}}
| 15
| 15
|}
|}


If you're using an increment, you need to give it to <code>#resetcount</code> too:
If you're using an increment, you need to give it to #resetcount too:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#resetcount:starting evens|14|2}}</code>
| {{#resetcount:starting evens&#124;14&#124;2}}
|
|  
|-
|-
| <code>{{#count:starting evens|2}}</code>
| {{#count:starting evens&#124;2}}
| 14
| 14
|-
|-
| <code>{{#count:starting evens|2}}</code>
| {{#count:starting evens&#124;2}}
| 16
| 16
|-
|-
| <code>{{#count:starting evens|2}}</code>
| {{#count:starting evens&#124;2}}
| 18
| 18
|-
|-
| <code>{{#count:starting evens|2}}</code>
| {{#count:starting evens&#124;2}}
| 20
| 20
|-
|-
| <code>{{#count:starting evens|2}}</code>
| {{#count:starting evens&#124;2}}
| 22
| 22
|}
|}


Use a negative increment to count down. As noted above, be sure to pass the increment to <code>#resetcount</code> too:
Use a negative increment to count down. As noted above, be sure to pass the increment to #resetcount too:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#resetcount:countdown|3|-1}}</code>
| {{#resetcount:countdown&#124;3&#124;-1}}
|
|  
|-
|-
| <code>{{#count:countdown|-1}}</code>
| {{#count:countdown&#124;-1}}
| 3
| 3
|-
|-
| <code>{{#count:countdown|-1}}</code>
| {{#count:countdown&#124;-1}}
| 2
| 2
|-
|-
| <code>{{#count:countdown|-1}}</code>
| {{#count:countdown&#124;-1}}
| 1
| 1
|-
|-
| <code>{{#count:countdown|-1}}</code>
| {{#count:countdown&#124;-1}}
| 0
| 0
|-
|-
| <code>{{#count:countdown|-1}}</code>
| {{#count:countdown&#124;-1}}
| -1
| -1
|}
|}
Line 241: Line 224:
You can use the counter in other [[ParserFunctions|parser functions]]:
You can use the counter in other [[ParserFunctions|parser functions]]:


{| class="wikitable" border="1" style="border-collapse: collapse"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code>
| {{#ifexpr:{{#count:alternate}} mod 2 = 0&#124;even&#124;odd}}
| odd
| odd
|-
|-
| <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code>
| {{#ifexpr:{{#count:alternate}} mod 2 = 0&#124;even&#124;odd}}
| even
| even
|-
|-
| <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code>
| {{#ifexpr:{{#count:alternate}} mod 2 = 0&#124;even&#124;odd}}
| odd
| odd
|-
|-
| <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code>
| {{#ifexpr:{{#count:alternate}} mod 2 = 0&#124;even&#124;odd}}
| even
| even
|-
|-
| <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code>
| {{#ifexpr:{{#count:alternate}} mod 2 = 0&#124;even&#124;odd}}
| odd
| odd
|}
|}


{| class="wikitable" border="1" style="border-collapse: collapse; margin-top: 1em"
{| class="wikitable"
|- style="background: #EEE"
|-
! Code
! Code
! Gives
! Gives
|-
|-
| <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code>
| {{#expr:{{#count:squares}} * {{#count:squares&#124;0}}}}
| 1
| 1
|-
|-
| <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code>
| {{#expr:{{#count:squares}} * {{#count:squares&#124;0}}}}
| 4
| 4
|-
|-
| <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code>
| {{#expr:{{#count:squares}} * {{#count:squares&#124;0}}}}
| 9
| 9
|-
|-
| <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code>
| {{#expr:{{#count:squares}} * {{#count:squares&#124;0}}}}
| 16
| 16
|-
|-
| <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code>
| {{#expr:{{#count:squares}} * {{#count:squares&#124;0}}}}
| 25
| 25
|}
|}


<span id="sortable-tables"></span>
== Sortable Tables ==
== <span class="mw-headline">Sortable Tables</span> ==


When using count in [[HRWiki:SORT|sortable tables]], please use the {{[[Template:hcount|hcount]]}} and {{[[Template:vcount|vcount]]}} templates. Be sure to carefully read their documentation in order to sort table entries correctly.
When using count in [[HRWiki:SORT|sortable tables]], please use the {{[[Template:hcount|hcount]]}} and {{[[Template:vcount|vcount]]}} templates. Be sure to carefully read their documentation in order to sort table entries correctly.
 
[[Category:Help]]
<div id="catlinks" class="catlinks">
 
<div id="mw-normal-catlinks">
 
[/wiki/Special:Categories Category]: <span dir="ltr">[[Category:Help|Help]]</span>
 
</div>
 
</div>



Latest revision as of 14:24, 14 July 2026

Usage

{{#count:id|increment}} Increments the counter id by increment and displays the result; increment can be omitted, and defaults to 1.
{{#resetcount:id|value|increment}} Silently sets the counter id to value minus increment (so that the next count by increment will display value); value and increment can be omitted, and both default to 1.
{{hcount}}
{{vcount}}
Used in sortable tables. See [#Sortable_Tables below].

Examples

count is a parser function that returns an integer that increments each time the function is called:

Code Gives
{{#count:basic}} 1
{{#count:basic}} 2
{{#count:basic}} 3
{{#count:basic}} 4
{{#count:basic}} 5

The counters can be given different names, so you can have more than one of them on the same page:
(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)

Code Gives
{{#count:first}} 1
{{#count:second}} 1
{{#count:second}} 2
{{#count:second}} 3
{{#count:first}} 2
{{#count:second}} 4

You can also make the counter count by twos, or by any other number:

Code Gives
{{#count:evens|2}} 2
{{#count:evens|2}} 4
{{#count:evens|2}} 6
{{#count:evens|2}} 8
{{#count:evens|2}} 10

Different increments can be used at different times, depending on what is needed:

Code Gives
{{#count:strange|1}} 1
{{#count:strange|1}} 2
{{#count:strange|3}} 5
{{#count:strange|0}} 5
{{#count:strange|-1}} 4
{{#count:strange|2}} 6

The counter can be reset partway through a page:

Code Gives
{{#count:basic}} 1
{{#count:basic}} 2
{{#count:basic}} 3
{{#resetcount:basic}}
{{#count:basic}} 1
{{#count:basic}} 2
{{#count:basic}} 3

You can also set what number you want to start on:

Code Gives
{{#resetcount:starting|11}}
{{#count:starting}} 11
{{#count:starting}} 12
{{#count:starting}} 13
{{#count:starting}} 14
{{#count:starting}} 15

If you're using an increment, you need to give it to #resetcount too:

Code Gives
{{#resetcount:starting evens|14|2}}
{{#count:starting evens|2}} 14
{{#count:starting evens|2}} 16
{{#count:starting evens|2}} 18
{{#count:starting evens|2}} 20
{{#count:starting evens|2}} 22

Use a negative increment to count down. As noted above, be sure to pass the increment to #resetcount too:

Code Gives
{{#resetcount:countdown|3|-1}}
{{#count:countdown|-1}} 3
{{#count:countdown|-1}} 2
{{#count:countdown|-1}} 1
{{#count:countdown|-1}} 0
{{#count:countdown|-1}} -1

You can use the counter in other parser functions:

Code Gives
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} odd
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} even
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} odd
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} even
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} odd
Code Gives
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} 1
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} 4
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} 9
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} 16
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} 25

Sortable Tables

When using count in sortable tables, please use the {{hcount}} and {{vcount}} templates. Be sure to carefully read their documentation in order to sort table entries correctly.