Template:Space altitude calculator

From Terraria Wiki
Jump to navigation Jump to search
Important.svg
CAUTION: Terraria Wiki code is complex!!!
If you want to use this code on another wiki, wiki.gg staff are not able to assist you.
Please consider picking a different wiki to adapt code from, or making your own templates!
Remember that content on a wiki is more important than fancy formatting.
Template-info.svg Documentation The documentation below is transcluded from Template:Space altitude calculator/doc. (edit | history)

This template is used to translate the relative altitude thresholds of the Space layer (see Space § Notes) into concrete values in feet for a given world. It requires some JavaScript code in MediaWiki:Common.js to be functional.

The concrete values are different for every world due to the randomized world generation. For instance, in one world the top of the world may be 2000' above the surface, while in another world it may be at 2200'. This has implications for all of the Space features. For instance, one player may need to ensure their Depth Meter reads at least 1100' in order for them to catch a Space-exclusive quest fish, whereas another player can already catch it at 1000'. It can be a bit tedious to calculate those thresholds manually or one-by-one, which this template aims to assist with.

It works by adding one input field, where the reader enters the altitude of the top of their specific world, and one or more (as many as desired) output texts with altitude factors (0.0, i.e. surface line, to 1.0, i.e. top of the world). The output texts are updated immediately when the input is changed.

Usage

Input field

{{ space altitude calculator | input = <text and field> | nojsmessage = <text for missing JavaScript> }}

input

Format of the input. This parameter must contain the string $input$, which will be replaced by the actual input field. Hence the minimum for this parameter (just the input field and no text) is |input=$input$. Some text should also be provided for clarity, though; see examples below. Especially the string $nojsmessage$ should be included somewhere in this parameter; it will be replaced by the value of the nojsmessage parameter. Beware that the input field will be on its own line if this template is used within a normal paragraph. Surround this template with <div> ... </div> to fix that.

nojsmessage

Text that is displayed if JavaScript is disabled in the browser or the code is missing on the wiki. Normally this will not be visible (or only very briefly when loading the page) in almost all cases, but is still important for those few cases when JavaScript is missing, as input and calculation will not work.

Output texts

{{ space altitude calculator | output = <text> | altitude = <decimal> }}

output

Format of the output. This parameter should contain the string $output$, which will be replaced by the calculated altitude in feet. If that string is missing, then the output will always be the same, regardless of the input.

altitude

Percentage of the area between the surface line and the top of the world, expressed as a decimal between 0.0 and 1.0. This is the factor by which the input altitude (which represents 1.0, or 100%) is multiplied.

Examples

The first input field (under "Simple demonstration") will not be functional, because the template is not intended to be used more than once on a page.

Simple demonstration

* {{space altitude calculator|input=At the top of the world, the Depth Meter reads $input$ feet. $nojsmessage$|nojsmessage=(Error! JavaScript might be disabled.)}}
  • At the top of the world, the Depth Meter reads
    feet. (Error! JavaScript might be disabled.)
* ... are at: {{space altitude calculator|altitude=0.5|output=exactly $output$ feet.}}
  • 50% between the surface line and the top of the world are at:
    exactly feet.
* ... are at: {{space altitude calculator|altitude=1.0|output=exactly $output$ feet.}}
  • 100% between the surface line and the top of the world are at:
    exactly feet.
* ... are at: {{space altitude calculator|altitude=0.031415926|output=exactly $output$ feet.}}
  • 3.1415926% between the surface line and the top of the world are at:
    exactly feet.

Complete example

: {{space altitude calculator|input=Input: {{gameText|GameUI.Depth|x_0=$input$}} {{gameText|GameUI.LayerSpace}} $nojsmessage$|nojsmessage={{note|paren=y|Error! JavaScript might be disabled.}}}}

{| class="wikitable"
! Altitude !! Notes
|-
| 100%
{{space altitude calculator|altitude=1.0|output={{gameText|GameUI.Depth|x_0=$output$}}}}
|
* Note 1
* Note 2
|-
| > 75%
{{space altitude calculator|altitude=0.75|output=> {{gameText|GameUI.Depth|x_0=$output$}}}}
|
* Note 3
* Note 4
|-
| < 50%
{{space altitude calculator|altitude=0.5|output=< {{gameText|GameUI.Depth|x_0=$output$}}}}
|
* Note 5
* Note 6
|}
Input:
'
Space (Error! JavaScript might be disabled.)
Altitude Notes
100%
'
  • Note 1
  • Note 2
> 75%
> '
  • Note 3
  • Note 4
< 50%
< '
  • Note 5
  • Note 6