Mabinogi World Wiki is brought to you by Coty C., 808idiotz, our other patrons, and contributors like you!!
Want to make the wiki better? Contribute towards getting larger projects done on our Patreon!

Template:CalcFormula/doc

From Mabinogi World Wiki

Description

Enters a formula for the CalcSystem.

Example

   {{CalcScopeStart}}
   {{CalcFormula|plustimes2|B + V * 2}}
   <div>{{CalcInput|V|4}}</div>
   <div>Base 2: {{CalcResult|plustimes2|B:2}}</div>
   <div>Base 5: {{CalcResult|plustimes2|B:5}}</div>
   {{CalcScopeEnd}}

plustimes2:B + V * 2

name=V;default=4
Base 2: formula=plustimes2;B:2
Base 5: formula=plustimes2;B:5

Parameters

Parameter # Usage Important?
1 Name of the formula that will be used for CalcResults Yes
2 Formula itself. See below for details. Yes

Formulas

In quick summary: This is JavaScript math allowing all functions from the Math object (do not prefix with "Math.")

For the rest of you who don't know what that means (it's okay!), here's some real documentation!

Formulas support the basic math operations, variables, and a few functions.

Operand Name
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
? : Ternary operation

Though I hope you know what the first four are, you may be wondering what modulo is. Well, it's the operation that finds the remainder of a division! For example, 3%4 = 3, 4%4 = 0, 5%4 = 1, and so on. Please note that JavaScript's modulo operator does not handle negatives as expected.

Ternary operations are complex as well. It is essentially of the form (condition ? non-zero case : zero case) Being that there are no comparisons, you can check equivalence with subtraction. Some may be added in the future.

Next we should talk about variables... if you've taken algebra then you have a primer, but there's no need to solve for x here. They're simply used to insert the value from a CalcInput, CalcSlider, etc (we'll call them CalcVars from now on) field, as well as any the CalcResult field defines itself. To be specific, it's the first parameter in any CalcVar field, and the left hand side of the entries in the list of the second parameter in CalcResult.

{{CalcInput|Var|3}} and {{CalcResult|formula|V:3;C:2}}

As in our example far above, we have a formula with two variables, B and V. V is defined by user input, that is, the CalcInput. B, however, is defined by the CalcResult. With the default settings, the formula B + V * 2 is rendered as 2 + 4 * 2 for the first CalcResult, executed, and the result is placed in that CalcResult's field.

Functions may be more complicated in some respects, but they're there just in case! Here is the list of functions supported:

Function Description
abs(n) Absolute value of the input. That is, the positive value.
acos(n) The inverse (or arc) cosine. This is trigonometry stuff.
asin(n) The inverse sine. More trig.
atan(n) The inverse tangent. More trig.
atan2(y,x) Returns the arctangent of the quotient of its arguments.
cos(rads) Cosine. More trig.
sin(rads) Sine. More trig.
tan(rads) Tangent. More trig.
round(f) Round a float (number with a decimal point) to the nearest integer (number without).
ceil(f) Round up to the nearest integer.
floor(f) Round down to the nearest integer; truncate decimal portion.
float(x,d) Return a formatted float with exactly d decimal places. Extra places are truncated.
exp(x) E to the x. I think that's trig? Highish level math anyway.
log(x) The natural logarithm of x; log base E of x.
min(x,y,...) Returns the smallest (minimum) value in the passed set.
max(x,y,...) Returns the largest (maximum) value in the passed set.
minn(n,x,y,...) Returns the nth smallest value in the passed set.
maxn(n,x,y,...) Returns the nth largest value in the passed set.
pow(x,y) Returns x to the power of y.
sqrt(x) Return the square root of x.
random() Return a random number between 0 and 1. (Tip: Between 0 and x is round(random() * x))

There are also some global variables courtesy of the Math object. These are E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1_2, SQRT2. Explaining these is really outside of the scope of this documentation, but you may use them like any other variables. Note that if you define a variable with the same name, it will be used instead of the global variable.