Size: 6187
Comment:
|
Size: 7789
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from Math | |
Line 21: | Line 22: |
||[[#FormatMiles|FormatMiles]] ||int ||Converts number to a string, e.g. "2.34 miles". || ||[[#FormatNumber|FormatNumber]] ||int ||Formats number with specified precision, e.g. "2,346". || ||[[#FormatNumber2|FormatNumber2]] ||int ||Formats numbers with 2 decimal places, e.g. "2,345.56". || ||[[#FormatPercent|FormatPercent]] ||int ||Formats number as percentage, e.g. "9.1%". || |
|
Line 33: | Line 38: |
Line 114: | Line 118: |
Line 119: | Line 122: |
Line 155: | Line 157: |
Line 160: | Line 161: |
= log = '''Usage:''' Returns the natural logarithm of the parameter val. '''Example:''' . '''Result:''' . |
= pow = '''Usage:''' Computes and returns base to the power of pow. '''Example:''' . '''Result:''' . = FormatMiles = '''Usage:''' !FormatMiles(number) Converts number to a string like "2.34 miles". '''Example:''' .echo !FormatMiles(123) .echo !FormatMiles(123.4) '''Result:''' .12:42:57 123.00 miles .12:42:58 123.40 miles = FormatNumber = '''Usage:''' !FormatNumber(number, optional precision = 0, optional useThousandsSeparator = true) Formats number with specified precision. Default has no decimal places, e.g. "2,346" '''Example:''' .echo !FormatNumber("1234567") .echo !FormatNumber("1234567","2") '''Result:''' .12:23:01 1,234,567 .12:23:02 1,234,567.00 = FormatNumber2 = '''Usage:''' !FormatNumber2(number, optional precision = 0, optional useThousandsSeparator = true) Formats number with 2 decimal places, e.g. "2,345.56". '''Example:''' .echo !FormatNumber2("1234567") '''Result:''' .12:40:14 1,234,567.00 = FormatPercent = '''Usage:''' !FormatPercent(number, optional presision = 1) Formats number as percentage. '''Example:''' .echo !FormatPercent("1") .echo !FormatPercent("0.25","0") .echo !FormatPercent("0.25","2") '''Result:''' .12:17:57 100.0% .12:17:58 25% .12:17:59 25.00% |
Line 226: | Line 278: |
echo round(random*10) | echo round(random()*10) |
Line 244: | Line 296: |
Line 245: | Line 298: |
Line 246: | Line 300: |
Line 253: | Line 308: |
Line 254: | Line 310: |
Line 255: | Line 312: |
Line 297: | Line 355: |
ScriptSyntax | ---- CategoryFunctions |
The following functions can be used to perform arithmetic on objects and variables.
These should be written in the following formats:
variable.method(arguments), example - ...
object.method(arguments), example - ...
Click each method name in the table below for more details of it, with examples.
Methods
Method |
Type |
Description |
|
|
int |
Computes and returns an absolute value for the number specified by the parameter val. |
|||
int |
Computes and returns the arc cosine of the number specified in the parameter val, in radians. |
|||
int |
Computes and returns the arc sine for the number specified in the parameter val, in radians. |
|||
int |
Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val. |
|||
int |
Computes and returns the angle of the point y/x in radians, when measured counterclockwise from a circle's x axis (where 0,0 represents the center of the circle). |
|||
int |
Returns the ceiling of the specified number or expression. |
|||
int |
Computes and returns the cosine of the specified angle in radians. |
|||
int |
Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x. |
|||
int |
Returns the floor of the number or expression specified in the parameter val. |
|||
int |
Converts number to a string, e.g. "2.34 miles". |
|||
int |
Formats number with specified precision, e.g. "2,346". |
|||
int |
Formats numbers with 2 decimal places, e.g. "2,345.56". |
|||
int |
Formats number as percentage, e.g. "9.1%". |
|||
int |
Returns the natural logarithm of the parameter val. |
|||
int |
Evaluates val1 and val2 (or more values) and returns the largest value. |
|||
int |
Evaluates val1 and val2 (or more values) and returns the smallest value. |
|||
int |
Computes and returns base to the power of pow. |
|||
int |
Returns a pseudo-random number n, where 0 <= n < 1. |
|||
int |
Rounds the value of the parameter val up or down to the nearest integer and returns the value. |
|||
int |
Computes and returns the sine of the specified angle in radians. |
|||
int |
Computes and returns the square root of the specified number. |
|||
int |
Computes and returns the tangent of the specified angle. |
abs
Usage:
Computes and returns an absolute value for the number specified by the parameter val.
Example:
echo abs(-123456)
echo abs(123456)
Result:
123456
123456
acos
Usage:
Computes and returns the arc cosine of the number specified in the parameter val, in radians.
Example:
Result:
asin
Usage:
Computes and returns the arc sine for the number specified in the parameter val, in radians.
Example:
Result:
atan
Usage:
Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter val.
Example:
Result:
atan2
Usage:
Returns a string comprising the characters represented by the Unicode character codes in the parameters.
Example:
Result:
ceil
Usage:
Returns the ceiling of the specified number or expression. Basically this means return the number rounded up to next whole number
Example:
echo ceil(4.1)
Result:
5
cos
Usage:
Computes and returns the cosine of the specified angle in radians.
Example:
Result:
exp
Usage:
Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.
Example:
Result:
floor
Usage:
Returns the floor of the number or expression specified in the paraenthesis... Floor is the whole number part, without the decimals. Basically means chop the decimal portion of the number off.
Example:
echo floor(1234.56)
Result:
1234
pow
Usage:
Computes and returns base to the power of pow.
Example:
Result:
FormatMiles
Usage: FormatMiles(number)
Converts number to a string like "2.34 miles".
Example:
echo FormatMiles(123)
echo FormatMiles(123.4)
Result:
- 12:42:57 123.00 miles
- 12:42:58 123.40 miles
FormatNumber
Usage: FormatNumber(number, optional precision = 0, optional useThousandsSeparator = true)
Formats number with specified precision. Default has no decimal places, e.g. "2,346"
Example:
echo FormatNumber("1234567")
echo FormatNumber("1234567","2")
Result:
- 12:23:01 1,234,567
- 12:23:02 1,234,567.00
FormatNumber2
Usage: FormatNumber2(number, optional precision = 0, optional useThousandsSeparator = true)
Formats number with 2 decimal places, e.g. "2,345.56".
Example:
echo FormatNumber2("1234567")
Result:
- 12:40:14 1,234,567.00
FormatPercent
Usage: FormatPercent(number, optional presision = 1)
Formats number as percentage.
Example:
echo FormatPercent("1")
echo FormatPercent("0.25","0")
echo FormatPercent("0.25","2")
Result:
- 12:17:57 100.0%
- 12:17:58 25%
- 12:17:59 25.00%
max
Usage:
Evaluates val1 and val2 (or more values) and returns the largest value.
Example:
echo max( city.troop.scouter, 100k )
Result:
If city.troop.scouter (the current number of scouts in the city) < 100k, then max( city.troop.scouter, 100k ) will return the number of scouts in city. If city.troop.scouter >= 100k then it will return 100000
min
Usage:
Evaluates val1 and val2 (or more values) and returns the smallest value.
Example:
echo min(city.resource.food.amount,99999999)
Result:
this will return whichever is smaller, 99,999,999 or the current amount of food in the city
pow
Usage:
Computes and returns base to the power of pow.
Example:
Result:
random
Usage:
Returns a pseudo-random number n, where 0 <= n < 1.
Example:
echo round(random()*10)
Result:
a random number between 0 and 9
round
Usage:
Rounds the value of the parameter val up or down to the nearest integer and returns the value. Optional argument to specify precision (or number of decimal places).
Example:
echo round(6.66666666666666666666)
echo round(6.66666666666666666666,1)
echo round(6.66666666666666666666,2)
echo round(6.66666666666666666666,3)
Result:
7
6.7
6.67
6.667
sin
Usage:
Computes and returns the sine of the specified angle in radians.
Example:
Result:
sqrt
Usage:
Computes and returns the square root of the specified number.
Example:
Result:
tan
Usage:
Computes and returns the tangent of the specified angle.
Example:
Result: