Template:Sell expr

来自Terraria Wiki
跳到导航 跳到搜索
此模板使用了 Lua。
此模板使用了用 Lua 编程语言编写的 模块:Coin expr。要了解 Lua 的更多信息,参见 en:Terraria Wiki:Lua
Template-info.svg 文档 以下文档来自Template:Sell expr/doc。(编辑 | 历史

This template can be used to handle elaborate expressions in conjunction with item sell values. The sell values are generated using {{iteminfo}}, hence they are dynamic and are adjusted accordingly should they be altered in a future Terraria update.

It aims at simplifying the convoluted syntax that is required for displaying sell value expressions: {{coin|{{#expr:{{iteminfo|Pixie Dust|value|raw=y}}/5*99+{{iteminfo|Crystal Shard|value|raw=y}}/5*33}}}} can be shortened to {{sell expr|Pixie Dust|*99+|Crystal Shard|*33}} using this template.

For handling buy prices instead of sell values, use {{buy expr}}. The syntax and usage is exactly the same.

Usage

{{ sell expr | <item name or ID 1> | <expression operators/constants/etc. 1> | ... | ... | <item name or ID n> | <expression operators/constants/etc. n> | raw = y/yes (optional) | round = <digit to round to> (optional) }}

1st, 3rd, 5th, 7th, ..., nth unnamed parameter

Name or ID of an item whose sell value is to be inserted at that part of the expression. Can be empty.

2nd, 4th, 6th, 8th, ..., (n+1)-th unnamed parameter

Operators, constants, etc. – valid {{#expr:}} syntax. Can be empty.

raw

Suppress the {{coin}} wrapping and instead display the numerical value, e.g. for use in other expressions.

round

Rounding functionality of {{coin}}, see Template:Coin for documentation and examples. Has no effect when using raw=y.

Concept

Example: Multiply the sum of the sell values of 3 Pixie Dust and 1 Crystal Shard by 5 and add the sell value of 7 Souls of Light.

Think of writing the expression normally:

{{#expr: 5*( <Pixie Dust sell value>*3 + <Crystal Shard sell value> ) + <Soul of Light sell value>*7 }}

For this template, simply replace the <item name sell value> parts with |<item name>|:

{{sell expr| 5*( |Pixie Dust|*3 + |Crystal Shard| ) + |Soul of Light|*7 }}

Now check if the first unnamed parameter is still an item name or ID. If it is not, add an empty parameter to fix that:

{{sell expr| | 5*( |Pixie Dust|*3 + |Crystal Shard| ) + |Soul of Light|*7 }}

Result:

1 GC9 SC

Proof: 5*( 1 SC *3 + 16 SC ) + 2 SC *7   =   5*( 19 SC ) + 14 SC   =   95 SC + 14 SC   =   1 GC9 SC

Notes

  • The template will display an error if the first, third, etc. unnamed parameters are not names or IDs of items. It will display 0 CC if the second, fourth, etc. unnamed parameters are not valid {{#expr:}} syntax.
  • {{iteminfo}} can only handle items that are present in 电脑版 电脑版 1.4.4.9. Using items exclusive to non-Desktop platforms will cause a template error.
  • The {{coin}} template (used for final formatting) does not handle negative values, so the final result must be above zero.

Examples

See Guide:Making money for many more examples.
Code Result
{{sell expr| Terra Blade }} 20 GC
{{sell expr| True Excalibur|+|True Night's Edge }} 20 GC
{{sell expr|| (|Excalibur|+|Broken Hero Sword|) + (|Night's Edge|+|Broken Hero Sword|) }} 23 GC60 SC
{{sell expr|| (12*|Hallowed Bar|+|Broken Hero Sword|) + ((|Blade of Grass|+|Volcano|+|Light's Bane|+|Muramasa|)+|Broken Hero Sword|) }} 22 GC90 SC
{{sell expr| Wood|*5 }} 0 CC
{{sell expr| 12*|Terra Blade }} (1st parameter not an item name or ID, 2nd parameter an item name) (template error)
{{sell expr|| 12*|Terra Blade }} (fixed the above) 2 PC40 GC
{{sell expr||||     | ||  ||| 6*   ||||| Terra Blade |||||*2 ||}} (parameters can be empty) 2 PC40 GC
{{sell expr| Terra Blade|*|12 }} (typo: 12 is treated as an item ID here) 10 PC
{{sell expr| Tizona|+|Sharanga }} (items not available on Desktop 1.4.4.9) (template error)
{{sell expr| Terra Blade|×12 }} (not valid syntax) 0 CC
{{sell expr| Terra Blade |raw=y}} 200000