Module:DefInfo/doc
This is the documentation page for Module:DefInfo
This might be called a beta version, leaning towards an alpha.
Bugs are quite possible but I've tested a bit and looks ok. Functionality expanded to actually be usable.
Performance: can be optimized but seems to be quite fast (will test more in bigger templates).
Code esthetics: ignore for now.
Description
This module is used to get information about game objects. Its main purpose is to populate the contents of infoboxes.
Values retrieved are those defined in the files so they may need to be processed to be user friendly. For example "foodType" that holds the value "OmnivoreRoughAnimal" is not entirely helpful. (TODO: This could be automatically converted to something more recognizable.)
Usage
query
{{#invoke:DefInfo|query|<defName>|...|<tag>|<sibling=...>}}
- <defName>
- defName of the Def.
- ...
- Additional arguments are here to help uniquely identify the final argument <tag>. If the wanted tag is already unique within a Def tree, then additional parameters are not needed.
- <tag>
- This is the key to be retrieved. They are the same as those in the XML files (filtered, of course; not all of the data from the files is available).
- <sibling=...>
- Allows querying for something if we know a sibling value (works only for values at the moment, keys might get added). It does not have to be at the end because named arguments do not depend on the order. (Might move this functionality to a separate function if the need arises).
The algorithm will return the first value found. If the query generates a list, for now, the default behaviour is to dump the contents of the thing to the log. The log can be accessed when previewing a page you're editing. A hint that this has happened (there is something in the log) is that the module returned the string "table".
getDefName
{{#invoke:DefInfo|getDefName|<label>}}
- <label>
- get defName based on the label of a Def (not case sensitive)
count
{{#invoke:DefInfo|count|<defName>|...|<tag>|<sibling=...>}}
Arguments are the same as for query. It's basically a wrapped up query.
- <defName>
- defName of the Def.
- ...
- Additional arguments are here to help uniquely identify the final argument <tag>. If the wanted tag is already unique within a Def tree, then additional parameters are not needed.
- <tag>
- This is the key to be retrieved. They are the same as those in the XML files (filtered, of course; not all of the data from the files is available).
- <sibling=...>
- Allows querying for something if we know a sibling value (works only for values at the moment, keys might get added). It does not have to be at the end because named arguments do not depend on the order. (Might move this functionality to a separate function if the need arises).
The generated list will also be displayed in the log.
Examples
strings, numbers, booleans
{{#invoke:DefInfo|query|Fox_Fennec|description}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|query|Fox_Fennec|MoveSpeed}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|query|Caribou|herdAnimal}}
- Script error: The module returned a nil value. It is supposed to return an export table.
"herdAnimal" is located in a branch of the main Def called "races" but because it appears nowhere else in the Def no additional parameters are needed to uniquely identify it. The following query retrieves the same data (just as an example) but with the use of an additional argument.
{{#invoke:DefInfo|query|Caribou|race|herdAnimal}}
- Script error: The module returned a nil value. It is supposed to return an export table.
numbered lists (tradeTags)
{{#invoke:DefInfo|query|GuineaPig|tradeTags}}
- Script error: The module returned a nil value. It is supposed to return an export table.
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
{{#invoke:DefInfo|count|GuineaPig|tradeTags}}
- Script error: The module returned a nil value. It is supposed to return an export table.
Count also shows the table in the log. To get the second item:
{{#invoke:DefInfo|query|GuineaPig|tradeTags|2}}
- Script error: The module returned a nil value. It is supposed to return an export table.
sibling queries (lifeStageAges, tools, etc.)
{{#invoke:DefInfo|query|GuineaPig|minAge|sibling=AnimalAdult}}
- Script error: The module returned a nil value. It is supposed to return an export table.
Same destination, different road:
{{#invoke:DefInfo|query|GuineaPig|lifeStageAges|3|minAge}}
- Script error: The module returned a nil value. It is supposed to return an export table.
Some examples for "tools" (attacks):
{{#invoke:DefInfo|count|Mech_Scyther|tools}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|count|Mech_Scyther|tools|1|capacities}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|1}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|2}}
- Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=LeftBlade}}
- Script error: The module returned a nil value. It is supposed to return an export table.
Same result:
{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=left blade}}
- Script error: The module returned a nil value. It is supposed to return an export table.
getDefName
{{#invoke:DefInfo|getDefName|fennec fox}}
- Script error: The module returned a nil value. It is supposed to return an export table.