User:DeKaitlyn/Notes/Substitution Magic

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
Meeting notes.png
This page contains personal notes.
The information contained are the personal notes of DeKaitlyn, and as such, are not to be treated as completely factual information, and thus may not make any sense to others.

Note: The below quotes have been modified just the slightest, to use correct capitalisation where possible, and to flow slightly better. The quotes were from Discord, in what used to be the #mining-and-smithing channel, under the Projects category, which may or may not exist by the time you are reading this.

Example[edit | edit source]

Used to AWB Beta equipment pages for the Mining and Smithing Beta 2.0

{{Disassembly
|level={{subst:#switch:{{subst:#explode:{{subst:PAGENAME}}| |0}}|Bronze=1|Iron=10|Steel=20|Mithril=30|Adamant=40|Rune=50|Orikalkum=60|Necronium=70|Bane=80|Elder=90}}
|category={{subst:#switch:{{subst:#explode:{{subst:#replace:{{subst:#replace:{{subst:replace|{{subst:PAGENAME}}|\+ \d|}}|<nowiki/> off hand}}|<nowiki/> rune}}| |1|-1}}
|platebody=melee body
|plateskirt|platelegs=melee legs
|armoured boots=melee boots
|square shield|kiteshield|round shield=melee shield
|gauntlets=melee gloves
|med helm|helm|full helm=melee helm
|2h greataxe|2h warhammer=maul
|#default={{subst:#explode:{{subst:#replace:{{subst:#replace:{{subst:replace|{{subst:PAGENAME}}| \+ \d|}}|<nowiki/> off hand}}|<nowiki/> rune}}| |1|-1}}}}
}}

This should work on every msrework item, which is what I'm gonna AWB now. Every bronze->erune (elder rune) item that is

Gaz

1Fpt65P.png
Example of when saving a page.

Example of the string used when mass redirecting beta pages to the non-beta versions.
#redirect [[{{subst:PAGENAME}}]]

Explanation[edit | edit source]

The important line is {{subst:#explode:{{subst:#replace:{{subst:#replace:{{subst:replace|{{subst:PAGENAME}}|\+ \d|}}|<nowiki/> off hand}}|<nowiki/> rune}}| |1|-1}} (which appears twice)

Gaz

From inside out, it takes the pagename and replaces \+ \d (an almost-regex) with nothing, then replaces off hand with nothing, then replaces rune with nothing, then splits the text by spaces and returns the 1st to last of it. So for Adamant off hand battleaxe + 1, it would go...

Gaz

Adamant off hand battleaxe + 1
Adamant off hand battleaxe
Adamant battleaxe
Adamant battleaxe
battleaxe

After all that, it runs a switch which replaces some things with the correct disassembly category. The other line, level, is just

{{subst:#switch:{{subst:#explode:{{subst:PAGENAME}}| |0}}|Bronze=1|Iron=10|Steel=20|Mithril=30|Adamant=40|Rune=50|Orikalkum=60|Necronium=70|Bane=80|Elder=90}}, which takes the first word of the pagename and replaces it with corresponding level.

Gaz

Subst takes each thing and replaces the code with the actual value when the page is saved. I don't really have any guide specifically for horrible subst[1] messes like this, its mostly a cobbling together of parser[2][3] and string functions[4].

Gaz

You may find use in https://runescape.wiki/w/User:Gaz_Lloyd/Guides/Calculators, it covers some stuff

Gaz

References[edit | edit source]