Difference between revisions of "Module:Test/doc"

From RimWorld Wiki
Jump to navigation Jump to search
m
m (added documentation for count)
Line 2: Line 2:
  
 
== Description ==
 
== Description ==
 
 
This module is used to get information about game objects.
 
This module is used to get information about game objects.
 
Its main purpose is to populate the contents of infoboxes.
 
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 "OminvoreRoughAnimal" is not entirely helpful.
+
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 "OminvoreRoughAnimal" is not entirely helpful. (TODO: This could be automatically converted to something more recognizable.)
 
 
If the queried value is not a simple one (strings, numbers or booleans), 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) may be that the modlue returned the string "table".
 
  
 
== Usage ==
 
== Usage ==
 
 
=== query ===
 
=== query ===
 
 
<pre><nowiki>
 
<pre><nowiki>
 
{{#invoke:Test|query|<defName>|...|<tag>}}
 
{{#invoke:Test|query|<defName>|...|<tag>}}
Line 26: Line 21:
 
; <tag>
 
; <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).
 
: 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).
 +
 +
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 modlue returned the string "table".
  
 
=== getDefName ===
 
=== getDefName ===
 
 
<pre><nowiki>
 
<pre><nowiki>
 
{{#invoke:Test|getDefName|<label>}}
 
{{#invoke:Test|getDefName|<label>}}
Line 35: Line 31:
 
; <label>
 
; <label>
 
: get defName based on the label of a Def (not case sensitive)
 
: get defName based on the label of a Def (not case sensitive)
 +
 +
=== count ===
 +
<pre><nowiki>
 +
{{#invoke:Test|count|<defName>|...|<tag>}}
 +
</nowiki></pre>
 +
 +
Arguments are the same as for 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).
 +
 +
The generated list will also be displayed in the log.
  
 
== Examples ==
 
== Examples ==
Line 54: Line 68:
  
 
=== numbered lists (tradeTags) ===
 
=== numbered lists (tradeTags) ===
* TODO: define syntax to get list length
+
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|tradeTags}}
 +
 
 +
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
 +
 
 +
;<code><nowiki>{{#invoke:Test|count|GuineaPig|tradeTags}}</nowiki></code>
 +
:{{#invoke:Test|count|GuineaPig|tradeTags}}
 +
 
 +
Count also shows the table in the log. To get the second item:
 +
 
 +
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags|2}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|tradeTags|2}}
  
 
=== sibling queries (lifeStageAges or tools) ===
 
=== sibling queries (lifeStageAges or tools) ===

Revision as of 04:46, 16 April 2021

This module is used for development. Even if it works at the moment it might break at any time.

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 "OminvoreRoughAnimal" is not entirely helpful. (TODO: This could be automatically converted to something more recognizable.)

Usage

query

{{#invoke:Test|query|<defName>|...|<tag>}}
<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).

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 modlue returned the string "table".

getDefName

{{#invoke:Test|getDefName|<label>}}
<label>
get defName based on the label of a Def (not case sensitive)

count

{{#invoke:Test|count|<defName>|...|<tag>}}

Arguments are the same as for 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).

The generated list will also be displayed in the log.

Examples

strings, numbers, booleans

{{#invoke:Test|query|Fox_Fennec|description}}
{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}
{{#invoke:Test|query|Caribou|herdAnimal}}

"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:Test|query|Caribou|race|herdAnimal}}

numbered lists (tradeTags)

{{#invoke:Test|query|GuineaPig|tradeTags}}

Query function returned "table" so its contents is displayed in the log (for reference). To get the length:

{{#invoke:Test|count|GuineaPig|tradeTags}}

Count also shows the table in the log. To get the second item:

{{#invoke:Test|query|GuineaPig|tradeTags|2}}

sibling queries (lifeStageAges or tools)

  • TODO: define syntax

getDefName

{{#invoke:Test|getDefName|fennec fox}}
Script error: The function "getDefName" does not exist.