Template talk:GetItemInfo

From Terraria Wiki
Jump to navigation Jump to search

Page Update?

I would like to ask if the stats info table is up to date as there are a few stats that seem to be missing. Examples that I could find: active, buy, height, instanced, isAShopItem, lavaWet, material, paintCoating, prefix, rarity, shootEveryUse, shopSpecialCurrency, tooltipContext, wet, wetCount, width. Also, this stat: throw, has been removed.

The order of the stats is a little weird and I think it should just stick to alphabetical order. It would be helpful if a default values column was also added, like in Module:Iteminfo and adding some better explainations of how the values in stats work. Example of a better stat explaination is the row for "crit" in Module:Iteminfo, which explains the base citical chance is 4% so a crit value of 0 keeps it a 4% with the value increasing it by a percent per number.

I find this template useful for a Terraria item data project I'm working on so I'd really appreciate it if this page were to be updated. I'm not an expert on wiki editing so I can't really do this myself. I'm also unsure what some of these missing stats would mean anyway. Sorry if this is unecessary or a mistake, thanks though. - Nix/Xinix (talk) 01:03, 31 October 2024 (UTC)

Yes, the stats table was getting a bit outdated. Thanks for mentioning; I updated it. Properties like instanced, prefix, or wet are dependent on the circumstances in-game, like the item's current modifier (prefix). These aren't needed here.
I added a column with default values to the Module:Iteminfo documentation. I don't think that column would be useful here on the Template:Iteminfo documentation, because this template is meant for directly displaying formatted values on the wiki, whereas the "raw" mode (i.e. Module:Iteminfo) returns unformatted values that can be processed further, which is where the default values matter.
--Rye Greenwood (talk) 07:16, 7 June 2025 (UTC)

Issue about raw price info display

The raw display for buy and sell is bugged for some reason: buy displays nothing, sell displays the item's buy value. BadPiggy1024 (talk) 03:33, 14 August 2025 (UTC)

Code Display
{{iteminfo|Grappling Hook|buy}} 2 GC
{{iteminfo|Grappling Hook|sell}} 40 SC
{{iteminfo|Grappling Hook|buy|raw=y}}
{{iteminfo|Grappling Hook|sell|raw=y}} 20000
Thank you for reporting! That's a curious issue. It stems from how the template should interpret buy and sell. Below I go into detail about how the problem is caused by how the template was designed, but it's a bit of a longer read, so here's the summary:
TL;DR: {{iteminfo}} stats are mostly tied to item attributes from Terraria's source code, but there are no buy and sell attributes in the source code. That's why I'd recommend not to use buy or sell with |raw=yes at all and to use {{buy expr}} and {{sell expr}} instead (with |raw=yes if needed). We can also make {{iteminfo|Grappling Hook|sell|raw=yes}} invalid entirely so that it displays nothing instead of the current confusing output, if you agree?
So I'm going to formulate the "philosophy" of the template's design in three points to illustrate the problem:
A. Each item attribute has a canonical name, like in Terraria's source code. By using these canonical names together with |raw=yes we can retrieve the respective values exactly (more or less) like they exist in the source code. Example for the rarity stat, whose canonical name is rare: {{iteminfo|Grappling Hook|rare|raw=yes}} → 1.
B. Because these canonical names aren't always easy/intuitive to use, there are a number of aliases. We can use e.g. rarity with the same result as with rare ({{iteminfo|Grappling Hook|rarity|raw=yes}} → 1), or use e.g. pick/pickpower/pickaxe power interchangeably.
C. Usually we don't need the original, raw values from the source code, and instead want to format them in some way. The template does that when |raw=yes is omitted. The formatted rarity text Blue (Rarity level: 1) ({{iteminfo|Grappling Hook|rare}} – without |raw=yes) is much nicer than the raw "1", for instance.
I believe these three points encompass the primary functionality of the template, and all of it works fine for almost all stats.
Where it gets tricky are buy and sell values. In the source code we only have the value attribute, which represents the buy price in Copper Coins. Point A still applies: {{iteminfo|Grappling Hook|value|raw=yes}} returns the raw value attribute from the source code: "20000", as expected.
Points B and C are not so easy, though. How should we format value to be usable for wiki display? Internally the attribute is kind of ambiguous. It is used as the buy price in Copper Coins for most items, but then some items aren't purchased with coins at all but with Defender Medals instead, which is where shopCustomPrice takes priority and value no longer accurately represents the buy price. At the same time, value is indirectly used to compute the sell value in Copper Coins by dividing it by 5 and then rounding down, but never rounding to below 1 Copper Coin.
So, according to the design philosophy, what should the template display when you use {{iteminfo|Grappling Hook|value}} without |raw=yes? Value usually means how much something is worth, or how much money you get in return for something, from the player's perspective of course – and not how much the NPC vendor gets in return for the thing. Therefore as an editor I would expect that {{iteminfo|Grappling Hook|value}} gives me the Grappling Hook's sell value. Hence, the algorithm for point C in the case of value is: Format it by integer-dividing by 5 but not to below 1, and wrap the result in {{coin}}.
Good, that is quite satisfactory. What about aliases for this attribute? According to point B, we should be able to use aliases to make the usage more intuitive. A very straightforward one is sell. I should be able to use {{iteminfo|Grappling Hook|sell}} to display the sell value, just like with {{iteminfo|Grappling Hook|value}}. Sure, that's sensible – but coming back to |raw=yes we now have a problem. Since we established sell=value, using {{iteminfo|Grappling Hook|sell|raw=yes}} now gives us the raw value attribute (as that template call now means the same thing as {{iteminfo|Grappling Hook|value|raw=yes}}). However, as before, value really isn't a sell value. It's this intermediate kind-of-buy-price-but-not-always and also basis-for-computing-the-sell-value.
This is exactly what you're showing above. {{iteminfo|Grappling Hook|sell|raw=yes}} shows the raw value and is thereby counter-intuitive, while at the same time being intuitive without |raw=yes.
For now I'll move on to buy prices. We defined the behavior of {{iteminfo|Grappling Hook|value}} and {{iteminfo|Grappling Hook|sell}}, but surely there needs to be a way to retrieve an item's buy price somehow. The question is: how can we do that while still adhering to the three design points? Again, internally the value attribute mostly represents the buy price in Copper Coins, and we're complying with point A by having {{iteminfo|Grappling Hook|value|raw=yes}} display that raw attribute, but for point C we run into the problem that {{iteminfo|Grappling Hook|value}} without |raw=yes is already occupied. The only solution is – point B – an alias. The obvious choice is buy, analogous to sell. Right, so we can define the algorithm for point C for buy: Wrap value in {{coin}}, unless shopCustomPrice is non-zero, in which case wrap that one in {{dm}} instead.
Good, now {{iteminfo|Grappling Hook|buy}} gives us the buy price in coins or Defender Medals as expected, but this way the buy alias is essentially detached from the value attribute. That goes a bit against the original template design philosophy but it's not a big deal. However, what does cause an issue is |raw=yes. Since buy is not tied to any attribute from the source code, what would {{iteminfo|Grappling Hook|buy|raw=yes}} display? Nothing, that's what. Once more, we can see that in your demo above.

{{iteminfo}} is meant to stay close to the source code. I hope my long-winded explanation demonstrates how that creates a problem in the case of the ambiguous value attribute and how the "raw" modes of the buy and sell aliases clash because of that.
As for a solution? Honestly, my recommendation is to avoid buy and sell with |raw=yes entirely. The only use cases I see for that are item price/value calculations, and {{buy expr}} and {{sell expr}} are designed exactly for that. A little bonus: those two templates also have a "raw" mode, so using {{buy expr|Grappling Hook|raw=yes}} and {{sell expr|Grappling Hook|raw=yes}} returns exactly what you'd expect (albeit still not for Defender Medal items!). This could circumvent {{iteminfo}}'s issues completely, should there still be a situation where these raw values are needed. I do suppose it's a bit hacky though, seeing as that isn't the templates' intended purpose.
I'd also be up for prohibiting {{iteminfo|Grappling Hook|sell|raw=yes}} in particular, so that it displays nothing rather than the counter-intuitive raw value. What do you think?
By the way, this reminded me of why {{buy expr}} and {{sell expr}} were even created in the first place: User talk:Rye Greenwood#Template:Iteminfo on Guide:Making money. It's an old thread and some things in there aren't correct anymore (like that the raw mode doesn't accept aliases), but it might still be interesting.
--Rye Greenwood (talk) 02:59, 15 August 2025 (UTC)
Thanks for the long, detailed answer! I'd agree with prohibiting raw sell output to reduce confusion and "incorrect" usage. Maybe we should also add {{buy expr}} and {{sell expr}} to document page to prevent editors from using {{iteminfo|<item>|buy/sell|raw=yes}}? BadPiggy1024 (talk) 04:28, 16 August 2025 (UTC)
Sure! I removed {{iteminfo|...|sell|raw=yes}} here and updated the template documentation here. --Rye Greenwood (talk) 03:42, 21 August 2025 (UTC)