• Hi,

    I'm trying to make a template for a user's garage: User:Geceo#Garage

    Is it possible to automatically compute the "speedrank" column given the "TS+N" and "rank" values? I know that the "stats" page have a "Top speed" that seems to be computed automatically but I don't understand how/where the magic is done.

    Note : I know that the speedrank is not very interesting nowadays, but it's just a simple example. There may be a more interesting formula to find, including the nitro efficiency and handling, to help the users identify their best possible MP vehicle…

      Loading editor
    • Yes, that's possible.

      Tables as such cannot calculate, templates can. The trick is to split the table into

      • a table header that only provides the header row and a closing bracket at the end
      • a table row that takes the values and calculates with them.

      {{Table header stats a8}} and {{Table row stats a8}} work this way, but they are perhaps a bad example because they are full of parameters for backwards compatibility.

      The simplest way would be:

      Header template {{header}}
      ! a
      ! b
      ! sum
      Row template {{row}}
      | {{{a|}}}
      | {{{b|}}}
      | {{#expr: {{{a|0}}} + {{{b|0}}} }}

      To display the table on a page, the code would be

        | {{row | a=2 | b=3}}
      • Note that templates use two curly brackets, parameters use three.
      • The parameter {{{1|}}} in the header means: It is the first unnamed parameter, hence the number. The pipe | means "if omitted, then display". Without pipe, the text "{{{1}}}" would be displayed if an editor omitted the parameter, which is mostly unwanted. The pipe says: If the first parameter is omitted, then display nothing.
      • In our example, we send the table row as parameter to the header which constructs the table.
      • a and b are named parameters. Normally it is more useful to use speaking parameters names. I chose a and b for simplicity.
      • The first table row column displays a or nothing, the second displays b or nothing, and the third builds the sum of a and b.
      • {{#expr: }} is not a template, but a parser function. You can recognize parser functions by the colon instead of the pipe. Many but not all parser functions are also preceded by a hashtag. {{#expr: }} is where your formulas go.
      • {{#expr: }} treats everything after the colon not as text like templates do but as something to compute. It needs "clean" parameters. We don't know if an editor forgets to provide one of the parameters, so just in case, we use a or zero ({{{a|0}}}) and b or zero ({{{b|0}}}), so there's always something to add. Otherwise, a nasty Expression error: Missing operand for +. could occur.
      • Wikipedia has much information about parser functions and what they can do.

      Good luck with your project and happy coding!

        Loading editor
    • Thanks, what a great answer! Very informative!

        Loading editor
    • Hi, I look at Template:Table row stats a8 and I don't understand why, in the section "This template", there are the "footnote" and a long list of "s Stock" below. Is that a problem in the documentation?

      UPDATE : "The new template can be shortened when all instances of "A8CarStats" have been replaced and Category:Pages using template A8CarStatsHeader is empty."

      Ok, it's time to shorten the new template I guess. :)

        Loading editor
    • Er... You got me there. I never completed the documentation. *cough*

      The long list of s parameters was just a placeholder for the real parameters to be added. Also, the big grey box with the parameter list under "Technical details" and the following text are a direct copy of the documentation of the old template. It still contains all superfluent parameters.

      Thanks for our great work replacing all instances of the old header template! Did you replace all table ROW templates as well? Ah, yes, I just checked.

      I deleted the two old templates. I suggest not to shorten the {{#switch:}} parameter list though, just in case some instances of the new template still use old parameters.

      But I'll leave the superfluent parameters undocumented so people only use the new ones.

        Loading editor
    • Wow, that's much better now! :)

        Loading editor
    • Still in progress.

      An I've seen that we cannot delete the old parameters. Some pages are still using some of them.

        Loading editor
    • But who cares. Few people read the code of s template. Although I am a friend of an esthetic code.

        Loading editor
    • Hi, just to let you know that I changed the "ultimate effect" background color in Nitro efficiency index (Asphalt 8) to a dark green gradient, because it wasn't easy to spot the best values with a mostly yellow gradient in a long list (check my garage to see the new gradient used in a list). Hopefully you'll agree.

        Loading editor
    • Oh, my first design was just inspired by the golden Ultimate label. In my own Excel file, the color is black with golden letters, but black has no effect on our black wiki pages, so I chose this one.

      You are right that the gold isn't easy to spot when placed next to yellow in a list.

        Loading editor
    • A FANDOM user
        Loading editor
Give Kudos to this message
You've given this message Kudos!
See who gave Kudos to this message
Community content is available under CC-BY-SA unless otherwise noted.