Jump to content

Module:Stat/doc

From Community Wiki | Soulbound: Online

This is the documentation page for Module:Stat

Renders game stat keys as player-facing names, units, ranges and rarity names. It holds the logic; the vocabulary it reads — labels, units, the rarity map — is in Module:Gear/data. Add a stat there, not here.

It replaced the long #switch chains that used to live in {{Stat}} , {{Stat/unit}}

and {{RollStat}}

. Each of those templates is now a single #invoke line with the same name and the same parameters, so no article needed changing.

Entry points

Call Used by Returns
{{#invoke:Stat|name|<key>}} {{Stat}} The stat's label — normally a link. An unknown key returns itself, unlinked, so a stat the wiki does not know about is visible rather than silently missing.
{{#invoke:Stat|unit|<key>}} {{Stat/unit}} % or an empty string. Unknown keys give an empty string.
{{#invoke:Stat|range|min|max|unit=%}} {{Range}} +(2–10)%. With max omitted, empty, or equal to min it collapses to a flat +10%. An empty min returns nothing at all.
{{#invoke:Stat|rollstat|<key>|min|max}} {{RollStat}} One sb-roll-stat chip: the stat's label, a space, then the range with the unit filled in from the stat's own entry. The dot between adjacent chips comes from CSS, not from here — callers must not type separators.
{{#invoke:Stat|rarity|<0-5>}} {{Rarity}} The colour-coded rarity name. 0 gives "None"; anything blank or outside 0–5 gives "Unknown" in the plain style rather than an error.

p._range(min, max, unit) is exported for Lua callers — a future module that needs the same +(2–10)% formatting should call it rather than re-implement the format.

Conventions this module owns

  • Signs. A positive value gets a +; a leading - is preserved as-is. Callers pass bare numbers and never their own sign.
  • Ranges are text, not numbers. They carry data-min and data-max attributes on the span for any future sorting or calculator work. Never run #expr over a range in wikitext — that is how other game wikis filled up with "Expression error".
  • Styling. Each function that emits markup attaches Template:ItemStyles/styles.css itself with frame:extensionTag, so a caller never has to remember a <templatestyles /> tag. That is also why the chip separator in the CSS must stay a general sibling selector (~): the injected style elements sit between the chips.

Changing it

Almost nothing that people want to change lives here. Adding a stat, renaming one, fixing a unit, or changing a rarity name is all Module:Gear/data. Come here only to change how something is formatted.

If you do: test in the debug console at the bottom of Module:Stat first (for example =p._range('2','10','%')), then preview a real page — Cursed Tritanium Sword exercises every function on this list — and confirm Category:Pages with script errors

is still empty afterwards.

See also