Help:Cargo: Difference between revisions
Humansongs (talk | contribs) m →Storing in a table: silly butiki |
|||
| (2 intermediate revisions by one other user not shown) | |||
| Line 4: | Line 4: | ||
==Storing data with Cargo== | ==Storing data with Cargo== | ||
Unlike a wikitext table, it is not possible for any user (even admins) to "edit" a Cargo table in the traditional sense. The only way to store data in a Cargo table is by using the <code><nowiki>{{#cargo_store}}</nowiki></code> parser function within a template (or a Lua module). This means adding, removing, or changing values in a table requires editing a template call on a page. For example, in order to change the cost of the "Perma-Spike" upgrade in the <code>btd6_upgrades</code> table, one needs to edit the <code>cost</code> parameter in the <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> template call on the [[Perma-Spike (BTD6)]] page, because the <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> template call on that page is what stores the information about that upgrade to the Cargo table. | |||
A template also needs to either declare the cargo table it will store content into, or attach itself to a cargo table that's defined in another template. For example, <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> is an infobox template that both declares the <code>btd6_upgrades</code> cargo table and stores the info for all those upgrades using template parameters. | |||
There are two major steps to setting up a cargo table: declaring the table and storing content in the table. This guide assumes you already know [[Help:Templates|how to create templates]]. | There are two major steps to setting up a cargo table: declaring the table and storing content in the table. This guide assumes you already know [[Help:Templates|how to create templates]]. | ||
| Line 68: | Line 70: | ||
|character_upgrade_required={{{character upgrade required|}}} | |character_upgrade_required={{{character upgrade required|}}} | ||
}}</pre> | }}</pre> | ||
The syntax is similar to a template call, except each parameter specifies which template parameters should pass their values into each column of the table. For example, [[Slicer]] | The syntax is similar to a template call, except each parameter specifies which template parameters should pass their values into each column of the table. For example, [[Slicer]] uses these parameters: | ||
<pre>{{BATTD upgrade info | <pre>{{BATTD upgrade info | ||
|id=slicer | |id=slicer | ||
| Line 82: | Line 84: | ||
}}</pre> | }}</pre> | ||
To explain in another way, this template call uses {{temp|BATTD upgrade info}} with the parameter <code>|cost=400</code>. This means the value <code>400</code> is both displayed in the infobox and stored in the <code>cost</code> column of the page, since both the infobox and the cargo store will substitute <code><nowiki>{{{cost|}}}</nowiki></code> with the value of the <code>|cost=</code> parameter. This works the same for every parameter except <code>id</code>, which isn't displayed in the infobox, but is still specified in the template call and stored in the table since it's necessary for cargo queries with other upgrades that use this template. | To explain in another way, this template call uses {{temp|BATTD upgrade info}} with the parameter <code>|cost=400</code>. This means the value <code>400</code> is both displayed in the infobox and stored in the <code>cost</code> column of the page, since both the infobox and the cargo store will substitute <code><nowiki>{{{cost|}}}</nowiki></code> with the value of the <code>|cost=</code> parameter. This works the same for every parameter except <code>id</code>, which isn't displayed in the infobox, but is still specified in the template call and stored in the table since it's necessary for cargo queries with other upgrades that use this template. | ||
You can see a list of Cargo rows that a specific page is storing by going to the "Cargo data" link in the toolbox. | |||
===Attaching to a table=== | ===Attaching to a table=== | ||
Latest revision as of 21:59, 25 October 2025
Blooncyclopedia uses Cargo to keep track of data in templates. Using Cargo queries, data stored in the site's database can be re-used without having to copy and paste it manually, and if the data needs to be edited (due to a patch being released or a correction being made), every page querying that data is automatically updated.
The cargo database can be seen by going to Special:CargoTables. Cargo tables cannot be directly modified; they pull their data from templates used elsewhere on the wiki, so in order to change something in a cargo table, you need to go to the page it is pulling that data from and change it. For example, if an upgrade cost in btd6_upgrades is incorrect, you can change it by going to the page for that upgrade and editing the cost in the infobox.
Storing data with Cargo
Unlike a wikitext table, it is not possible for any user (even admins) to "edit" a Cargo table in the traditional sense. The only way to store data in a Cargo table is by using the {{#cargo_store}} parser function within a template (or a Lua module). This means adding, removing, or changing values in a table requires editing a template call on a page. For example, in order to change the cost of the "Perma-Spike" upgrade in the btd6_upgrades table, one needs to edit the cost parameter in the {{BTD6 upgrade info}} template call on the Perma-Spike (BTD6) page, because the {{BTD6 upgrade info}} template call on that page is what stores the information about that upgrade to the Cargo table.
A template also needs to either declare the cargo table it will store content into, or attach itself to a cargo table that's defined in another template. For example, {{BTD6 upgrade info}} is an infobox template that both declares the btd6_upgrades cargo table and stores the info for all those upgrades using template parameters.
There are two major steps to setting up a cargo table: declaring the table and storing content in the table. This guide assumes you already know how to create templates.
Declaring a table
In order to set up a new table, it needs to be declared by using {{#cargo_declare}} inside a template page's <noinclude> section. This parser function defines each column of the table and what kind of data these columns can store. For example, {{BATTD upgrade info}}, which is the infobox template used for upgrades in Bloons Adventure Time TD, declares its table like this:
{{#cargo_declare:_table=battd_upgrades
|id=String
|name =String
|image =File
|description=String
|tower =String
|cost =Integer
|previous=List (,) of String
|locked_by_upgrades=List (,) of String
|level_required =Integer
|weapon_required =String
|trinket_required =String
|character_nearby_required =String
|character_upgrade_required=String
}}
The syntax is similar to a template call, except each parameter defines a column of the table. |description=String means "create a column named 'description' that can store data of type 'String'". Column names should be written in snake_case. There are many different data types (a full list can be found on the Mediawiki wiki), each with restrictions on what data can be stored, though all data types can also store null or empty values. The ones used in this example are:
| Type | Restriction |
|---|---|
String
|
A sequence of plain text, not containing any wiki markup, limited to 300 characters |
File
|
The name of a file on the wiki; this is functionally the same as a String, except when viewing the cargo table in Special:CargoTables, it will display the files themselves instead of just the file names, which is more convenient |
Integer
|
A whole number |
List (,) of String
|
A list of strings separated by commas with no spaces between them (e.g. "Apple,Banana,Orange") |
Note that declaring a table does not immediately create a table, though creating a table does require declaring it first. Any autoconfirmed user can declare a table, but only administrators can create or destroy tables.
Storing in a table
In order to store data in a cargo table, the template needs to use {{#cargo_store}} inside its <includeonly> section. When a page uses a template with a cargo store, the template adds a new row to the cargo table containing the values in the {{#cargo_store}} parser function. Typically, the values in the parser function are template parameters; that way, the parameters used for the template are passed into the table. For example, {{BATTD upgrade info}} stores its data like this:
{{#cargo_store:_table=battd_upgrades
|id={{{id|}}}
|name ={{{name|}}}
|image ={{{image|}}}
|description={{{description|}}}
|tower ={{{tower|}}}
|cost ={{{cost|}}}
|previous={{{previous|}}}
|locked_by_upgrades={{{locked by upgrades|}}}
|level_required ={{{level required|}}}
|weapon_required ={{{weapon required|}}}
|trinket_required ={{{trinket required|}}}
|character_nearby_required ={{{character nearby required|}}}
|character_upgrade_required={{{character upgrade required|}}}
}}
The syntax is similar to a template call, except each parameter specifies which template parameters should pass their values into each column of the table. For example, Slicer uses these parameters:
{{BATTD upgrade info
|id=slicer
|name =Slicer
|image =BATTD upgrade icon slicer.png
|description=Increases damage from sword attacks
|cost =400
|tower =Finn
|previous=limber_limbs,sword_player_1
|trinket required=Medallion of Brogends
}}
To explain in another way, this template call uses {{BATTD upgrade info}} with the parameter |cost=400. This means the value 400 is both displayed in the infobox and stored in the cost column of the page, since both the infobox and the cargo store will substitute {{{cost|}}} with the value of the |cost= parameter. This works the same for every parameter except id, which isn't displayed in the infobox, but is still specified in the template call and stored in the table since it's necessary for cargo queries with other upgrades that use this template.
You can see a list of Cargo rows that a specific page is storing by going to the "Cargo data" link in the toolbox.
Attaching to a table
If multiple templates need to store their data in one table, a template can use {{#cargo_store}} to store its data in a table declared by another template. For example, {{BATTD ally upgrade info}} stores its data in battd_upgrades, which is declared by {{BATTD upgrade info}}. You can also "attach" a template to another template's table via {{#cargo_attach}}. For example, {{BATTD ally upgrade info}} attaches itself to battd_upgrades via {{#cargo_attach:_table=battd_upgrades}}. This isn't required for the cargo storage to work, but it's recommended that you do so because it allows the template to appear in Special:CargoTables.
Since every page about an upgrade in Bloons Adventure Time TD uses {{BATTD upgrade info}}, and every page about an ally in Bloons Adventure Time TD uses {{BATTD ally upgrade info}} for their upgrades, the parameters they use to display the information in their infoboxes is also stored in the cargo table battd_upgrades. This is how you create a cargo table containing statistics for every upgrade in the game.
Querying data
Querying data is done using the {{#cargo_query}} parser function. Unlike defining and storing data, queries do not have to be in a template, though it's good practice to wrap them around a template if they're going to be used more than once.