Help:Cargo: Difference between revisions

attempted to explain the process of creating and storing data tables more concisely, since people don't seem to really understand how it works
m →Storing in a table: silly butiki
 
(4 intermediate revisions by one other user not shown)
Line 4: Line 4:


==Storing data with Cargo==
==Storing data with Cargo==
Storing data is done using the <code><nowiki>{{#cargo_store}}</nowiki></code> parser function within a template. This 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, {{temp|BTD6 upgrade info}} is an infobox template that both defines the <code>btd6_upgrades</code> cargo table and stores the info for all those upgrades using template parameters.
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. Once this is set up, then each page that uses this template will store the parameters they use for the template in the cargo table <code>battd_upgrades</code>. For [[Slicer]], that looks like this:
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 81: Line 83:
|trinket required=Medallion of Brogends
|trinket required=Medallion of Brogends
}}</pre>
}}</pre>
To describe what's going on 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>{{{cost|}}}</code> with the value of the <code>|cost=</code> parameter.
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===