Data Tables Guide

From Open Perpetuum

To make it easier to extract and manage game data (like robot and module stats) we are utilizing an extension called Cargo.

We are using these three basic functions:

  • #cargo_declare
    • This declares a cargo table. It can be generated by using the Special:CreateTemplate page
      • This page makes it easy to first generate the table, but it can't be used to edit an existing table. So it's easier to edit a table to add and remove some properties instead of re-creating it all from the UI.
    • This declare action must be done in a Template page. For consistency we are using template names like Table_DataType, for exmaple: Table_WeaponStats and Table_AmmoWeaponStats
    • Note that Cargo also supports data being compiled from multiple templates. When doing this, only one template can use the declare function, but multiple templates can use the attach function to add on to an existing table
  • #cargo_store
    • This adds a row to a cargo table.
    • Cargo is meant to follow one of two use cases: the pages are built up one at a time and then read into the cargo table, or by linking to a database to populate the cargo table
      • Because we do not want to deal with direct database access for our data tables, and we also do not plan to make a page for every type of ammo / module, neither of these approaches work for us.
      • Instead, we are using a single page to store the data for each type. The pages are named like Data_AmmoWeapons.
      • These pages are populated with multiple store commands which are generated from the Perpetuum Data Dumper.
      • This allows us to quickly update the data for each type with a single update instead of maintaining individual pages
  • #cargo_query
    • This is the real reason we are doing all of this. This allows us to query data from a table and display it.
    • The simplest use is to define a table header and use a cargo query with a specified row template to generate all the rows.
=== Small EM-gun ===
{{WeaponStandardHeader}}
{{#cargo_query:
|tables=WeaponStats
|fields=module_name,cpu,reactor,ammo_type,ammo_capacity,slot_type,slot_status,module_mass,module_volume_packed,module_tier,module_volume,module_accumulator,module_cycle,module_damage,module_falloff,module_hit_dispersion,module_optimal_range,module_extensions_required
|where=slot_size='small' AND module_categories HOLDS 'cf_railguns'
|order by=WeaponStats.module_tier, WeaponStats.module_name
|format=template
|template=WeaponStatsRow
|named args=yes
}}
|}
      • We can see that the header being used for the table is also defined in a template: Template:WeaponStandardHeader
      • We can see that the WeaponStats table is being referenced, and we can see the list of fields we want to pull
        • Note that these are called with an underscore in name and not spaces
        • We use the named args option to indicate that the Template:WeaponStatsRow template will refer to these fields by name instead of by index
        • There is a known bug that the Template used to define a query row should not use underscores in variable names. Instead of "item_name" it should be referenced as "item name"
      • We can use the where clause for filtering and the order by for data arrangement
    • We can also use a more advanced template with paramaters to build this entire table for us. For example:
{{AmmoWeaponStats
|AmmoCategory=cf_small_projectile_ammo
}}

which calls the Template:AmmoWeaponStats which builds he header, and calls the cargo query with the provided AmmoCategory.


You can view the Special:CargoTables page to see the tables, how many rows they have, which template(s) define the table, and which pages are loading rows.

You can also use the Special:Drilldown page to browse data tables and filter by various criteria.