Toggle search
Search
Toggle menu
Toggle personal menu
Editing
Data:Sample:RecipeProduction
From Desynced Wiki
Read
Edit source
View history
Data
Discussion
More actions
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.
Anti-spam check. Do
not
fill this in!
This page uses [[Template:DataRecipe]] to show a recipe by passing "Building 1x1 (2S)" <pre>{{DataRecipe|Building 1x1 (2S)}}</pre> {{DataRecipe|Building 1x1 (2S)}} [[Template:DataRecipe]] is the replacement for making a page like [[GameData:Recipe:Building_1x1_(2S)]]. Instead of having to use python scripts to create a new robot page and upload it each time you want more information, you can create a template like [[Template:DataRecipe]] The high-level steps are: # Add a template like [[Template:Recipe_Production_Test]], this is exactly the same as it was before # Create a template like [[Template:DataRecipe]] to fill in [[Template:Recipe_Production_Test]] ## Fill in a bunch of boilterplate (doesn't change much between templates like <code>cargo_query</code>) ## Choose which fields you want ## Tell cargo to rename them to your template's arguments ## Point the query to the actual template you created (like [[Template:Recipe_Production_Test]]) # Include that template on pages you wish <hr> Let's take a closer look at what [[Template:DataRecipe]] is actually doing. <pre> <includeonly> {{#cargo_query: tables={{GetTable|{{{1}}}}} |fields=name,ingredient1,amount1,ingredient2,amount2,ingredient3,amount3,ingredient4,amount4,producer1,time1,producer2,time2 |where=name='{{{1}}}' |format=template |template=Recipe_Production_Test |named args=yes }} </includeonly> </pre> What's happening here? There is a template called [[Template:Recipe_Production_Test]] that is just like [[Template:Recipe_Production]] except for a few renamed arguments because the character <code>-</code>(hyphen) is banned in cargo. That template needs a bunch of things: name of the thing, ingredients, how much of those, and producers. Here is the template: <pre> {{Recipe Production |name |ingredient1 |amount1 |ingredient2 |amount2 |ingredient3 |amount3 |ingredient4 |amount4 |producer1 |time1 |producer2 |time2 }} </pre> Our goal is: I want to fill in all the arguments I need for my template so I can render it. Let's look at the query line-by-line: <hr> <pre><includeonly></pre> See https://www.mediawiki.org/wiki/Transclusion#Partial_transclusion_markup, this has to do with transclusion. It says: Only render this when you include it on a page. <hr> <pre>{{#cargo_query:</pre> This is just like calling a template, but instead it's going to ask cargo for information. <hr> <pre>tables={{GetTable|{{{1}}}}}</pre> In order to ask cargo for information, we need to know which table from [[Special:CargoTables]] it's stored in. To help with that, there is [[Template:GetTable]] which does this for you[1]. Don't sweat the details, this always stays the same if you're looking up one thing. <hr> <pre>|fields=name,ingredient1,amount1,ingredient2,amount2,ingredient3,amount3,ingredient4,amount4,producer1,time1,producer2,time2</pre> Ok now we know which cargo table we're looking in (<code>entity</code> for the one example above). Now we can go to [[Special:CargoTables]] and click on our table: [[Special:CargoTables/entity]]. On that page there is a list of fields (there will be descriptions later) which you can pick from for your template. <pre> name - String health - Integer power_usage_per_second - Integer movement_speed - Float visibility - Float storage - Integer size - String race - String (allowed values: Robot 路 Alien 路 Bug 路 Human 路 Virus 路 Blight) types1 - String (allowed values: Bug 路 Bot 路 Building) types2 - String (allowed values: Bug 路 Bot 路 Building) large_sockets - Integer medium_sockets - Integer small_sockets - Integer internal_sockets - Integer slot_type - String (allowed values: None 路 Flyer 路 Drone 路 Satellite 路 Garage 路 Bughole) ingredient1 - String amount1 - Integer ingredient2 - String amount2 - Integer ingredient3 - String amount3 - Integer ingredient4 - String amount4 - Integer producer1 - String time1 - Integer producer2 - String time2 - Integer </pre> In this case I want the name and the recipe values. Looking back at the template: <pre> {{Recipe_Production_Test |name |ingredient1 |amount1 |ingredient2 |amount2 |ingredient3 |amount3 |ingredient4 |amount4 |produced-by1 |time1 |produced-by2 |time2 }} </pre> It turns out that the field names match[3] the template exactly, so all we have to do is list them in <code>fields</code>. More on this in a second. <hr> <pre> |where=name='{{{1}}}' </pre> This tells cargo to look up the <code>fields</code> we just listed only for the thing we care about. We're setting the name to the first argument passed to our template (the name). <hr> <pre> |format=template |template=Recipe_Production_Test |named args=yes </pre> Lets look at the last three together because they're related. First we tell cargo to take the <code>fields</code> we asked for and pass them to a template (<code>|format=template</code>), then we need to tell it which template (<code>|template=Recipe_Production_Test</code>) we want it to pass the information to. The last line <code>|named args=yes</code> just means: use the <code>fields</code> names when you pass it to the template. If youre template didn't use names and only did postitional arguments (<code>{{{1}}}, {{{2}}}</code>) you would leave the <code>named args</code> line out. It's worth noting that cargo has lots of display formats (https://www.mediawiki.org/wiki/Extension:Cargo/Display_formats) so you don't even have to write your own template if you don't want! <hr> [1] The TLDR on how it works is that there is a special tabled called [[Special:CargoTables/table_index]] that only has two columns: <code>name, stored_table</code> where name is the name of a page and stored_table is which cargo table it's stored in. [2] Well... how do I know which table my thing is? Often it might be obvious from the [[Special:CargoTables]] (it's a component, an item), but other times it might not (a building is an entity). One way to find the table is to just toss <code><nowiki>{{GetTable|My Thing}}</nowiki></code> into sany page and preview or into [[Special:ExpandTemplates]] and it'll spit out what table it's in the preview. This is something I want to improve. [3] It's not a problem if your fields don't match. Lets imagine they were called <code>item_amount1</code> instead of <code>amount</code>. All we have to do is add that to our <code>fields</code> line: <code>|fields=ingredient1,amount1=item_amount1,...</code> and now it'll automatically fill them in the template for us.
Summary:
Please note that all contributions to Desynced Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, 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 (see
Desynced Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:DataRecipe
(
edit
)
Template:GetTable
(
edit
)