HRWiki Counter: Difference between revisions
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 | <!-- Mirrored from Homestar Runner Wiki (hrwiki.org) via Wayback Machine --> | ||
== Usage == | |||
{| class="wikitable" | |||
{| class="wikitable | |||
|- | |- | ||
| | | {{#count:''id''|''increment''}} | ||
| Increments the counter ''id'' by ''increment'' and displays the result; ''increment'' can be omitted, and defaults to | | 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 | | 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. | ||
|- | |- | ||
| | | {{[[Template:hcount|hcount]]}}<br />{{[[Template:vcount|vcount]]}} | ||
| Used in [[HRWiki:SORT|sortable tables]]. ''See [#Sortable_Tables below].'' | |||
| Used in [[HRWiki:SORT|sortable tables]]. ''See [#Sortable_Tables below].'' | |||
|} | |} | ||
== Examples == | |||
= | |||
'''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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 3 | | 3 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 4 | | 4 | ||
|- | |- | ||
| | | {{#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 /> | ||
(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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#count:first}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:second}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:second}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:second}} | ||
| 3 | | 3 | ||
|- | |- | ||
| | | {{#count:first}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#count:evens|2}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:evens|2}} | ||
| 4 | | 4 | ||
|- | |- | ||
| | | {{#count:evens|2}} | ||
| 6 | | 6 | ||
|- | |- | ||
| | | {{#count:evens|2}} | ||
| 8 | | 8 | ||
|- | |- | ||
| | | {{#count:evens|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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#count:strange|1}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:strange|1}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:strange|3}} | ||
| 5 | | 5 | ||
|- | |- | ||
| | | {{#count:strange|0}} | ||
| 5 | | 5 | ||
|- | |- | ||
| | | {{#count:strange|-1}} | ||
| 4 | | 4 | ||
|- | |- | ||
| | | {{#count:strange|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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 3 | | 3 | ||
|- | |- | ||
| | | {{#resetcount:basic}} | ||
| | | | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:basic}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#resetcount:starting|11}} | ||
| | | | ||
|- | |- | ||
| | | {{#count:starting}} | ||
| 11 | | 11 | ||
|- | |- | ||
| | | {{#count:starting}} | ||
| 12 | | 12 | ||
|- | |- | ||
| | | {{#count:starting}} | ||
| 13 | | 13 | ||
|- | |- | ||
| | | {{#count:starting}} | ||
| 14 | | 14 | ||
|- | |- | ||
| | | {{#count:starting}} | ||
| 15 | | 15 | ||
|} | |} | ||
If you're using an increment, you need to give it to | If you're using an increment, you need to give it to #resetcount too: | ||
{| class="wikitable | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#resetcount:starting evens|14|2}} | ||
| | | | ||
|- | |- | ||
| | | {{#count:starting evens|2}} | ||
| 14 | | 14 | ||
|- | |- | ||
| | | {{#count:starting evens|2}} | ||
| 16 | | 16 | ||
|- | |- | ||
| | | {{#count:starting evens|2}} | ||
| 18 | | 18 | ||
|- | |- | ||
| | | {{#count:starting evens|2}} | ||
| 20 | | 20 | ||
|- | |- | ||
| | | {{#count:starting evens|2}} | ||
| 22 | | 22 | ||
|} | |} | ||
Use a negative increment to count down. As noted above, be sure to pass the increment to | Use a negative increment to count down. As noted above, be sure to pass the increment to #resetcount too: | ||
{| class="wikitable | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#resetcount:countdown|3|-1}} | ||
| | | | ||
|- | |- | ||
| | | {{#count:countdown|-1}} | ||
| 3 | | 3 | ||
|- | |- | ||
| | | {{#count:countdown|-1}} | ||
| 2 | | 2 | ||
|- | |- | ||
| | | {{#count:countdown|-1}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#count:countdown|-1}} | ||
| 0 | | 0 | ||
|- | |- | ||
| | | {{#count:countdown|-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 | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | ||
| odd | | odd | ||
|- | |- | ||
| | | {{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | ||
| even | | even | ||
|- | |- | ||
| | | {{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | ||
| odd | | odd | ||
|- | |- | ||
| | | {{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | ||
| even | | even | ||
|- | |- | ||
| | | {{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | ||
| odd | | odd | ||
|} | |} | ||
{| class="wikitable | {| class="wikitable" | ||
|- | |- | ||
! Code | ! Code | ||
! Gives | ! Gives | ||
|- | |- | ||
| | | {{#expr:{{#count:squares}} * {{#count:squares|0}}}} | ||
| 1 | | 1 | ||
|- | |- | ||
| | | {{#expr:{{#count:squares}} * {{#count:squares|0}}}} | ||
| 4 | | 4 | ||
|- | |- | ||
| | | {{#expr:{{#count:squares}} * {{#count:squares|0}}}} | ||
| 9 | | 9 | ||
|- | |- | ||
| | | {{#expr:{{#count:squares}} * {{#count:squares|0}}}} | ||
| 16 | | 16 | ||
|- | |- | ||
| | | {{#expr:{{#count:squares}} * {{#count:squares|0}}}} | ||
| 25 | | 25 | ||
|} | |} | ||
== Sortable Tables == | |||
= | |||
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]] | |||
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.