User:Sub4rctic/Any: Difference between revisions
No edit summary |
No edit summary |
||
(32 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<!-- | <includeonly> | ||
{{User:Sub4rctic/Woods}} | {{#vardefine:Item|{{#explode:{{{1}}}|,|0}}}} | ||
{{#vardefine:Quantity|{{#explode:{{{1}}}|,|1}}}} | |||
{{#vardefine:Png|{{#explode:{{{1}}}|,|2}}}} | |||
{{#vardefine:Wood_1|{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|){{#if:{{#var:Quantity}}|,{{#var:Quantity}}|}}{{#if:{{#var:Png}}|.png|}}}}|<|{{#var:Item}}<nowiki/> <nowiki/>(}}}} <!-- ITEM (WOOD) --> | |||
{{#switch: {{#var:Item}} | |||
| #default = Item not found | |||
| Barrel= {{#var:Wood_1}} | |||
| Chest = {{#var:Wood_1}} | |||
| Chopped Log = {{#var:Wood_1}} | |||
| Fence = {{#var:Wood_1}} | |||
| Fence Gate = {{#var:Wood_1}} | |||
| Large Log = {{#var:Wood_1}} | |||
| Log = {{#var:Wood_1}} | |||
| Loom = {{#var:Wood_1}} | |||
| Lumber = {{#var:Wood_1}} | |||
| Planks = {{#var:Wood_1}} | |||
| Sapling = {{#var:Wood_1}} | |||
| Support Beam = {{#var:Wood_1}} | |||
| Tool Rack = {{#var:Wood_1}} | |||
| Wooden Door = {{#var:Wood_1}} | |||
}} | |||
</includeonly> | |||
<noinclude> | |||
'''<code><nowiki>{{User:Sub4rctic/Woods}}</nowiki></code>''' | |||
List of all woods with < and > as PREFIX and SUFFIX, semicolon separated | List of all woods with < and > as PREFIX and SUFFIX, semicolon separated | ||
{{#replace:string|search term|replacement term}} | '''<code><nowiki>{{#replace:string|search term|replacement term}}</nowiki></code>''' | ||
replacement syntax | replacement syntax | ||
{{#replace:{{User:Sub4rctic/Woods}}|search term|replacement term}} | '''<code><nowiki>{{#replace:{{User:Sub4rctic/Woods}}|search term|replacement term}}</nowiki></code>''' | ||
use the woods template as the string | use the woods template as the string | ||
{{#replace:{{User:Sub4rctic/Woods}}|>|<nowiki/> <nowiki/>SUFFIX}} | '''<code><nowiki>{{#replace:{{User:Sub4rctic/Woods}}|>|<nowiki/> <nowiki/>SUFFIX}}</nowiki></code>''' | ||
If a space is used in the replacement term, must be nowiki'd out with self-closing tags | If a space is used in the replacement term, must be nowiki'd out with self-closing tags | ||
{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|SUFFIX}}|<|PREFIX}} | '''<code><nowiki>{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|SUFFIX}}|<|PREFIX}}</nowiki></code>''' | ||
nest SUFFIX replacement inside a PREFIX replacement | nest SUFFIX replacement inside a PREFIX replacement | ||
{{#explode:string|delimiter|position|limit}} | '''<code><nowiki>{{#explode:string|delimiter|position|limit}}</nowiki></code>''' | ||
explode syntax. Pos counted from 0 | explode syntax. Pos counted from 0 | ||
{{#explode:{{{1}}}|,|0}} | '''<code><nowiki>{{#explode:{{{1}}}|,|0}}</nowiki></code>''' | ||
Returns before comma | Returns before comma | ||
{{#explode:{{{1}}}|,|1}} | '''<code><nowiki>{{#explode:{{{1}}}|,|1}}</nowiki></code>''' | ||
returns string after comma | returns string after comma | ||
{{# | <pre> | ||
{{#vardefine:Item|{{#explode:{{{1}}}|,|0}}}} | |||
{{#vardefine:Quantity|{{#explode:{{{1}}}|,|1}}}} | |||
</pre> | |||
Set variables to make code more readable. | |||
'''<code><nowiki>{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|SUFFIX,{{#var:Quantity}}}}|<|PREFIX}}</nowiki></code>''' | |||
after the suffix add a comma and add param 1 string after comma. Problem: leaves a comma even when there is no ",#" after item name. | after the suffix add a comma and add param 1 string after comma. Problem: leaves a comma even when there is no ",#" after item name. | ||
{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }} | '''<code><nowiki>{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}</nowiki></code>''' | ||
if syntax | if syntax | ||
{{#if: {{# | '''<code><nowiki>{{#if: {{#var:Quantity}}|,{{#var:Quantity}}|}}</nowiki></code>''' | ||
if param 1 string after comma delimiter is not empty, return ", string", and if it is, return nothing | if param 1 string after comma delimiter is not empty, return ", string", and if it is, return nothing | ||
{{#replace: | '''<code><nowiki>{{#replace: {{#replace: {{User:Sub4rctic/Woods}}|>|SUFFIX{{#if:{{#var:Quantity}}|,{{#var:Quantity}}|}}}}|<|PREFIX}}</nowiki></code>''' | ||
}} | |||
so if param 1 has a comma then number, a comma and the number will be placed after SUFFIX. If not, then nothing will be placed after SUFFIX | so if param 1 has a comma then number, a comma and the number will be placed after SUFFIX. If not, then nothing will be placed after SUFFIX | ||
{{#switch: comparison string | <pre>{{#switch: comparison string | ||
| case = result | | case = result | ||
| case = result | | case = result | ||
| #default = default result | | #default = default result | ||
}} | }}</pre> | ||
Switch syntax | Switch syntax | ||
</noinclude> | |||
Latest revision as of 05:00, 9 October 2019
{{User:Sub4rctic/Woods}}
List of all woods with < and > as PREFIX and SUFFIX, semicolon separated
{{#replace:string|search term|replacement term}}
replacement syntax
{{#replace:{{User:Sub4rctic/Woods}}|search term|replacement term}}
use the woods template as the string
{{#replace:{{User:Sub4rctic/Woods}}|>|<nowiki/> <nowiki/>SUFFIX}}
If a space is used in the replacement term, must be nowiki'd out with self-closing tags
{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|SUFFIX}}|<|PREFIX}}
nest SUFFIX replacement inside a PREFIX replacement
{{#explode:string|delimiter|position|limit}}
explode syntax. Pos counted from 0
{{#explode:{{{1}}}|,|0}}
Returns before comma
{{#explode:{{{1}}}|,|1}}
returns string after comma
{{#vardefine:Item|{{#explode:{{{1}}}|,|0}}}} {{#vardefine:Quantity|{{#explode:{{{1}}}|,|1}}}}
Set variables to make code more readable.
{{#replace:{{#replace:{{User:Sub4rctic/Woods}}|>|SUFFIX,{{#var:Quantity}}}}|<|PREFIX}}
after the suffix add a comma and add param 1 string after comma. Problem: leaves a comma even when there is no ",#" after item name.
{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}
if syntax
{{#if: {{#var:Quantity}}|,{{#var:Quantity}}|}}
if param 1 string after comma delimiter is not empty, return ", string", and if it is, return nothing
{{#replace: {{#replace: {{User:Sub4rctic/Woods}}|>|SUFFIX{{#if:{{#var:Quantity}}|,{{#var:Quantity}}|}}}}|<|PREFIX}}
so if param 1 has a comma then number, a comma and the number will be placed after SUFFIX. If not, then nothing will be placed after SUFFIX
{{#switch: comparison string | case = result | case = result | #default = default result }}
Switch syntax