Editing Module:Test/doc

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
__NOEDITSECTION__
+
'''This module is used for development. Even if it works at the moment it might break at any time.'''
'''This module is used for development.'''
 
  
== Purpose ==
+
== Description ==
 +
This module is used to get information about game objects.
 +
Its main purpose is to populate the contents of infoboxes.
  
This module is used to query information from the uploaded and parsed game files.
+
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.)
 
 
Its main purpose is to populate the infoboxes.
 
  
 
== Usage ==
 
== Usage ==
 +
=== query ===
 +
<pre><nowiki>
 +
{{#invoke:Test|query|<defName>|...|<tag>|<sibling=...>}}
 +
</nowiki></pre>
  
A note on the order of named parameters. All of the parameters that look like <code>...=...</code> are called named parameters and their order is not important (this is true for all templates).
+
; <defName>
 +
: defName of the Def.
  
=== query ===
+
; ...
<pre><nowiki>{{#invoke:Test|query|<def ID>[|...|][|tag|][|sibling=...]}}</nowiki></pre>
+
: 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.
  
The work-horse. Output varies based on use:
+
; <tag>
: If only the <code><def ID></code> parameter is set, it will show the whole Def in the log.
+
: 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 simple values are queried it will return them.
 
: If lists are queried it will return nothing but call <code><nowiki>{{#vardefine}}</nowiki></code> on all the simple values within it. What got defined can be seen in the page's log.
 
  
Named parameters:
+
; <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).
  
: <code><def ID></code>
+
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".
  
:: This parameter identifies the Def so it is mandatory. It can take two forms, if both are defined then <code>defName</code> takes preference.
+
=== getDefName ===
 +
<pre><nowiki>
 +
{{#invoke:Test|getDefName|<label>}}
 +
</nowiki></pre>
  
::: <code>defName=<defName></code>
+
; <label>
:::: <code><defName></code> <small>''(case sensitive)''</small> should be replaced with the actual defName of a Def.
+
: get defName based on the label of a Def (not case sensitive)
  
::: <code>label=<label></code>
+
=== count ===
:::: <code><label></code> <small>''(case insensitive)''</small> should be replaced with the actual label of a Def.
+
<pre><nowiki>
 +
{{#invoke:Test|count|<defName>|...|<tag>|<sibling=...>}}
 +
</nowiki></pre>
  
: <code>[sibling=...]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
+
Arguments are the same as for query. It's basically a wrapped up query.
::: Allows querying for something if we know its sibling's value (works only for values at the moment).
 
  
Anonymous parameters:
+
; <defName>
 +
: defName of the Def.
  
: <code>[|...|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
+
; ...
:: Anonymous paramaters before the last one (<code>[tag]</code>) are here to help uniquely identify it. If the <code>[tag]</code> is already unique within a Def tree, then these additional parameters are not needed.
+
: 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.
  
: <code>[|tag|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
+
; <tag>
:: The final anonymous parameter defines what is to be queried.
+
: 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).
  
=== count ===
+
; <sibling=...>
<pre><nowiki>{{#invoke:Test|count|<def ID>[|...|][|tag|][|sibling=...]}}</nowiki></pre>
+
: 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).
  
Parameters are the same as for <code>query</code>. It's basically a wrapped up query that behaves a bit differently.
+
The generated list will also be displayed in the log.
  
The difference is in how it handles lists. If a list is queried, unlike <code>query</code>, it will return the length of the list.
+
== Examples ==
 +
=== strings, numbers, booleans ===
 +
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|description}}</nowiki></code>
 +
:{{#invoke:Test|query|Fox_Fennec|description}}
  
== How-to ==
+
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}</nowiki></code>
 +
:{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}
  
=== Take a look at a Def ===
+
;<code><nowiki>{{#invoke:Test|query|Caribou|herdAnimal}}</nowiki></code>
 +
:{{#invoke:Test|query|Caribou|herdAnimal}}
  
<code><nowiki>{{#invoke:Test|query|label=desert}}</nowiki></code>
+
"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.
  
<code>{{#invoke:Test|query|label=desert}}</code>
+
;<code><nowiki>{{#invoke:Test|query|Caribou|race|herdAnimal}}</nowiki></code>
 +
:{{#invoke:Test|query|Caribou|race|herdAnimal}}
  
Data is in the log.
+
=== numbered lists (tradeTags) ===
 +
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|tradeTags}}
  
=== Retrieve a simple value ===
+
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
  
<code><nowiki>{{#invoke:Test|query|defName=Caribou|description}}</nowiki></code>
+
;<code><nowiki>{{#invoke:Test|count|GuineaPig|tradeTags}}</nowiki></code>
 +
:{{#invoke:Test|count|GuineaPig|tradeTags}}
  
<code>{{#invoke:Test|query|defName=Caribou|description}}</code>
+
Count also shows the table in the log. To get the second item:
  
=== Dealing with lists ===
+
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags|2}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|tradeTags|2}}
  
<code><nowiki>{{#invoke:Test|query|defName=Mech_Scyther|tools}}</nowiki></code>
+
=== sibling queries (lifeStageAges, tools, etc.) ===
 +
;<code><nowiki>{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}
  
<code>{{#invoke:Test|query|defName=Mech_Scyther|tools}}</code>
+
Same destination, different road:
  
When a list is retrieved there will be no output but the log will contain a list of defined variables.
+
;<code><nowiki>{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}</nowiki></code>
 +
:{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}
  
For convenience the list is reprinted here:
+
Some examples for "tools" (attacks):
  
<pre>
+
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools}}</nowiki></code>
tools_1_linkedBodyPartsGroup = LeftBlade
+
:{{#invoke:Test|count|Mech_Scyther|tools}}
tools_1_cooldownTime = 2
 
tools_1_label = left blade
 
tools_1_DPS = 10
 
tools_1_power = 20
 
tools_1_capacities_1 = Cut
 
tools_1_capacities_2 = Stab
 
tools_2_linkedBodyPartsGroup = RightBlade
 
tools_2_cooldownTime = 2
 
tools_2_label = right blade
 
tools_2_DPS = 10
 
tools_2_power = 20
 
tools_2_capacities_1 = Cut
 
tools_2_capacities_2 = Stab
 
tools_3_linkedBodyPartsGroup = HeadAttackTool
 
tools_3_capacities_1 = Blunt
 
tools_3_label = head
 
tools_3_DPS = 4.5
 
tools_3_chanceFactor = 0.2
 
tools_3_power = 9
 
tools_3_cooldownTime = 2
 
</pre>
 
  
All of the above can be accessed with the use of <code><nowiki>{{#var:...}}</nowiki></code>.
+
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}</nowiki></code>
 +
:{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}
  
<code><nowiki>{{#var:tools_1_DPS}}</nowiki></code>
+
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}</nowiki></code>
 +
:{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}
  
<code>{{#var:tools_1_DPS}}</code>
+
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}</nowiki></code>
 +
:{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}
  
''DPS'' is not a normal member of this table but has been added with Lua. Let's call it a virtual field.
+
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}</nowiki></code>
 +
:{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}
  
=== Retrieve something if a sibling is known ===
+
Same result:
  
<code><nowiki>{{#invoke:Test|query|label=guinea pig|minAge|sibling=AnimalAdult}}</nowiki></code>
+
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}</nowiki></code>
 +
:{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}
  
<code>{{#invoke:Test|query|label=guinea pig|minAge|sibling=AnimalAdult}}</code>
+
=== getDefName ===
  
<includeonly>[[Category:Module]]</includeonly>
+
;<code><nowiki>{{#invoke:Test|getDefName|fennec fox}}</nowiki></code>
<noinclude>[[Category:Module documentation]]</noinclude>
+
:{{#invoke:Test|getDefName|feNNec fox}}

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)