模块:ItemNames

来自Terraria Wiki
跳到导航 跳到搜索
亦可参看英文模块:Module:ItemNames。那边可能有更完整或更正确的信息。

This module makes item name and ID information available. It should not be invoked normally in article text.

The module can be called from another module with the following function:

  • require('Module:ItemNames').getData('<table name>', <value>)
Returns the data for the given value from the given table. Available tables and expected values:
Code Result
getData('itemNameFromId', 3279) 'Malaise'
getData('itemIdFromName', 'Malaise') '3279'
getData('itemInternalNameFromId', 3279) 'CorruptYoyo'
getData('itemIdFromInternalName', 'CorruptYoyo') '3279'
Beware that item IDs are returned as strings, not integers.

The module can be called from wikitext with the following function:

  • {{#invoke:ItemNames| loadData | <table name> }}
Sets variables for all items for the given table, as demonstrated above. The variable names are prefixed with the table's name. For example, {{#invoke:ItemNames|loadData|itemNameFromId}} sets the variables {{#var:itemNameFromId:1}} (Iron Pickaxe), {{#var:itemNameFromId:2}} (Dirt Block), and so on, up to {{#var:itemNameFromId:5455}} (Guide to Peaceful Coexistence (Inactive)).
This function is only intended to be called from a template (one for each table), namely:

local itemdata = mw.loadData('Module:ItemNames/loaddata')
local VariablesLua = mw.ext.VariablesLua

return {
	loadData = function(frame)
		local tableName = frame.args[1]
		
		local data = itemdata[tableName]
		local prefix = tableName .. ':'
		
		for k, v in pairs(data) do
			VariablesLua.vardefine( prefix .. k, v)
		end
		
		VariablesLua.vardefine( prefix .. '__OK__', '__OK__')
	end,
	
	getData = function(tableName, value)
		return itemdata[tableName][value]
	end,
}