abs(n: int) -> int
The size of a number, ignoring its sign. abs(-5) and abs(5) are both 5.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to take the size of |
print("size", abs(-5))
66 math commands, generated from the engine's own registry — signatures, parameters and a worked example each. A does something command acts on the game; a needs x() one answers a confident wrong answer when its client hooks are missing.
abs(n: int) -> int
The size of a number, ignoring its sign. abs(-5) and abs(5) are both 5.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to take the size of |
print("size", abs(-5))
absDiff(a: int, b: int) -> int
How far apart two numbers are — the difference with the sign dropped, computed wide so opposite extremes cannot wrap. Faults when even that gap does not fit.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print(absDiff(3, 10))
approach(current: int, target: int, step: int) -> int
The current value moved towards the target by at most step, never overshooting. For easing a value in without a fraction.
| Parameter | Type | What it does |
|---|---|---|
| currentrequired | int | where it is now |
| targetrequired | int | where it is heading |
| steprequired | int | the most it may move this time |
print("eased", approach(0, 100, 10))
atan2Deg(dy: int, dx: int) -> int
The angle from one point toward another, in whole degrees 0 to 359 — 0 is right, 90 is up. Feed it the difference of two positions.
| Parameter | Type | What it does |
|---|---|---|
| dyrequired | int | how far down the target is (negative for up) |
| dxrequired | int | how far right the target is (negative for left) |
print(atan2Deg(0, 10))
average(a: int, b: int) -> int
The average of two numbers, rounded down, worked out so it cannot overflow on the way.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print("mid", average(10, 21))
between(value: int, low: int, high: int) -> bool
True when value is from low to high, ends included. Reads better than two comparisons joined with and.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to test |
| lowrequired | int | the lowest it may be |
| highrequired | int | the highest it may be |
if between(fatigue(), 80, 100) { print("nearly tired") }
binaryOf(n: int) -> string
A number written in base two, as text.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to show |
print("bits", binaryOf(5))
bitAnd(a: int, b: int) -> int
The bits set in both numbers — the bitwise AND, for reading a mask.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print("masked", bitAnd(prayerMask(), 2))
bitOr(a: int, b: int) -> int
The bits set in either number — the bitwise OR, for combining flags.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print("flags", bitOr(1, 4))
bitXor(a: int, b: int) -> int
The bits set in one number but not the other — the bitwise XOR.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print("toggled", bitXor(5, 1))
chebyshev(x1: int, y1: int, x2: int, y2: int) -> int
The distance between two points when diagonal steps count as one — the larger of the two differences, how RSC's own tiles measure reach.
| Parameter | Type | What it does |
|---|---|---|
| x1required | int | the first point's x |
| y1required | int | the first point's y |
| x2required | int | the second point's x |
| y2required | int | the second point's y |
print(chebyshev(0, 0, 3, 4))
clamp(value: int, low: int, high: int) -> int
The value held between low and high: below low it becomes low, above high it becomes high. Refuses when low is above high.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to hold within a range |
| lowrequired | int | the lowest it may be |
| highrequired | int | the highest it may be |
uiProgress("bag", clamp(120, 0, 100), 100)
combinations(n: int, k: int) -> int
How many ways k things can be chosen from n when order does not matter. Computed wide; faults when the answer does not fit.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | how many there are to choose from |
| krequired | int | how many are chosen |
print(combinations(5, 2))
commas(n: int) -> string
The number written with a comma every three digits, for a readout: 1234567 becomes 1,234,567.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to group |
print("gp", commas(1000000))
cosScaled(degrees: int, scale: int) -> int
The cosine of an angle multiplied up into a whole number — the partner of sinScaled, for circling a point.
| Parameter | Type | What it does |
|---|---|---|
| degreesrequired | int | the angle, in degrees |
| scalerequired | int | what to multiply the cosine by before rounding |
print(cosScaled(0, 1000))
countBits(n: int) -> int
How many bits are set in a number — its population count.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to read |
print("bits", countBits(255))
degreesBetween(a: int, b: int) -> int
The shortest turn between two angles, 0 to 180 — 350 and 10 are twenty degrees apart, not three hundred and forty.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first angle, in degrees |
| brequired | int | the second angle, in degrees |
print(degreesBetween(350, 10))
dice(sides: int) -> int
A random roll from 1 to the number of sides. Refuses fewer than one side.
| Parameter | Type | What it does |
|---|---|---|
| sidesrequired | int | how many sides, at least one |
print("roll", dice(6))
digits(n: int) -> int
How many digits a number has, ignoring any minus sign. digits(1000) is 4.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to measure |
print("width", digits(1000))
distance(x1: int, y1: int, x2: int, y2: int) -> int
The straight-line distance between two points, rounded to the nearest whole number — the screen-pixel partner of the tile distance.
| Parameter | Type | What it does |
|---|---|---|
| x1required | int | the first point's x |
| y1required | int | the first point's y |
| x2required | int | the second point's x |
| y2required | int | the second point's y |
print(distance(0, 0, 3, 4))
factorial(n: int) -> int
The factorial of a number — n times every number below it. Refuses below zero or above 20, where it stops fitting in a whole number.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number, 0 to 20 |
print("5!", factorial(5))
fib(n: int) -> int
The n-th Fibonacci number: fib(0) is 0, fib(1) is 1, each after is the sum of the two before. Faults past fib(92), the last that fits.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | which Fibonacci number, from 0 |
print(fib(10))
floorDiv(a: int, b: int) -> int
Whole division that rounds towards minus infinity, unlike '/' which rounds towards zero. floorDiv(-7, 2) is -4 where -7 / 2 is -3. Refuses divide by zero.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the number being divided |
| brequired | int | the number to divide by |
print("rows", floorDiv(0 - 7, 2))
floorMod(a: int, b: int) -> int
The remainder that always has the sign of b, unlike '%' which takes the sign of a. This is the one you want to cycle an index: floorMod(-1, 4) is 3, not -1. Refuses a zero wrap.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the number being wrapped |
| brequired | int | the number to wrap around |
let corner = floorMod(0 - 1, 4) print(corner)
gcd(a: int, b: int) -> int
The greatest common divisor of two numbers — the largest that divides both.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
print("gcd", gcd(24, 36))
hash(text: string) -> int
A repeatable number for a piece of text — the same text always gives the same number. For bucketing or a stable per-name choice, not for security.
| Parameter | Type | What it does |
|---|---|---|
| textrequired | string | the text to hash |
print("bucket", floorMod(hash("mining"), 4))
hexOf(n: int) -> string
A number written in base sixteen, as text.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to show |
print("hex", hexOf(255))
isEven(n: int) -> bool
True when a number divides by two exactly.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to test |
if isEven(4) { print("even") }
isOdd(n: int) -> bool
True when a number does not divide by two exactly.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to test |
if isOdd(3) { print("odd") }
isPowerOfTwo(number: int) -> bool
True when the number is exactly a power of two: 1, 2, 4, 8 and so on. Zero and negatives are not.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to test |
if isPowerOfTwo(64) { print("it is") }
isPrime(number: int) -> bool
True when the number is prime. Exact for every number the language holds — this is a real primality proof, not a guess — and instant even at the top of the range. Zero, one and negatives are not prime.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to test |
if isPrime(1000003) { print("prime") }
lerp(from: int, to: int, percent: int) -> int
The number a percentage of the way from one to another: lerp(0, 200, 25) is 50. Computed wide, so big ends cannot wrap; faults on overflow.
| Parameter | Type | What it does |
|---|---|---|
| fromrequired | int | the answer at 0 |
| torequired | int | the answer at 100 |
| percentrequired | int | how far along, 0 to 100 (outside runs past the ends) |
print(lerp(0, 200, 25))
log10(number: int) -> int
How many times 10 divides into a number, rounded down — one less than how many digits it has. Refuses zero and below.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to take the log of; 1 or more |
print(log10(2500))
log2(number: int) -> int
How many times 2 divides into a number, rounded down: log2(1000) is 9. Refuses zero and below, which have no logarithm.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to take the log of; 1 or more |
print(log2(1024))
manhattan(x1: int, y1: int, x2: int, y2: int) -> int
The distance between two points walking only along the axes — the sum of the two differences, how movement on a grid actually costs.
| Parameter | Type | What it does |
|---|---|---|
| x1required | int | the first point's x |
| y1required | int | the first point's y |
| x2required | int | the second point's x |
| y2required | int | the second point's y |
print(manhattan(0, 0, 3, 4))
mapRange(value: int, inLow: int, inHigh: int, outLow: int, outHigh: int) -> int
A number moved from one range onto another, keeping its proportion — 50 of 0..100 becomes 128 of 0..255. Rounded down; refuses a zero-width input range.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to remap |
| inLowrequired | int | the low end of its current range |
| inHighrequired | int | the high end of its current range |
| outLowrequired | int | the low end of the range to map into |
| outHighrequired | int | the high end of the range to map into |
print("scaled", mapRange(50, 0, 100, 0, 255))
max(a: int, b: int) -> intmax(a: int, b: int, d: int) -> int
The larger of two numbers.
The largest of three numbers — max of a pair already exists; this saves nesting it for a third.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
| drequired | int | the third number |
print("higher", max(3, 8))
print(max(3, 1, 2))
min(a: int, b: int) -> intmin(a: int, b: int, d: int) -> int
The smaller of two numbers.
The smallest of three numbers — min of a pair already exists; this saves nesting it for a third.
| Parameter | Type | What it does |
|---|---|---|
| arequired | int | the first number |
| brequired | int | the second number |
| drequired | int | the third number |
print("lower", min(3, 8))
print(min(3, 1, 2))
mulDiv(value: int, by: int, over: int) -> int
value times 'by', divided by 'over', computed wide so the middle cannot wrap — THE safe way to take a ratio of a big number. Faults on overflow and refuses dividing by zero.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to scale |
| byrequired | int | what to multiply by first |
| overrequired | int | what to divide by after; must not be zero |
print(mulDiv(1000000, 3, 4))
nextPowerOfTwo(number: int) -> int
The smallest power of two that is the number or bigger: 100 rounds to 128. Faults past the largest one a number can hold.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to round up |
print(nextPowerOfTwo(100))
nextPrime(number: int) -> int
The first prime STRICTLY after a number: nextPrime(10) is 11, nextPrime(11) is 13. Faults past the largest prime a number can hold.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | where to start looking, exclusive |
print(nextPrime(100))
numberIn(text: string) -> int?
The first run of digits in a line as a number, ignoring commas, or none when there is no number. 'You now have 1,234 coins' reads as 1234.
| Parameter | Type | What it does |
|---|---|---|
| textrequired | string | the text to scan for a number |
if numberIn("you have 5 coins") == none { return 600 }
oneIn(n: int) -> bool
True about one time in n, at random. oneIn(100) is a one-percent chance. Refuses fewer than one.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the odds — one in this many |
if oneIn(50) { print("rare") }
padded(n: int, width: int) -> string
The number right-aligned in spaces to at least the given width, so rows of them line up in a label. A number already wider is unchanged.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to pad |
| widthrequired | int | the least number of characters wide |
uiLabel("count", padded(7, 4))
parseInt(text: string) -> int?
The whole number a string spells, or none when it is not a plain number. Test the none the way you would test a nearest-thing that was not found.
| Parameter | Type | What it does |
|---|---|---|
| textrequired | string | the text to read a number from |
if parseInt("42") == none { print("not a number") }
percentOf(part: int, whole: int) -> int
What percentage part is of whole, from 0 to 100, rounded down. Refuses a zero whole, which has no percentage.
| Parameter | Type | What it does |
|---|---|---|
| partrequired | int | the amount so far |
| wholerequired | int | the amount that would be a full hundred percent |
uiProgress("done", percentOf(15, 30), 100)
permutations(n: int, k: int) -> int
How many ways k things can be picked from n when order matters. Computed wide; faults when the answer does not fit.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | how many there are to choose from |
| krequired | int | how many are placed in order |
print(permutations(5, 2))
pickWeighted(values: list<int>, weights: list<int>) -> int?
One of the values at random, each as likely as its weight — pickWeighted of 600, 900 with weights 3, 1 answers 600 three times in four. None for empty lists; refuses mismatched sizes and negative weights.
| Parameter | Type | What it does |
|---|---|---|
| valuesrequired | list<int> | the numbers one of which is answered |
| weightsrequired | list<int> | how likely each is, matching one for one; 0 never |
print(pickWeighted(range(0, 3), range(1, 4)))
pow(base: int, exponent: int) -> int
The base raised to the exponent, as a whole number. Refuses a negative exponent (that is a fraction) and faults if the result is too big to hold.
| Parameter | Type | What it does |
|---|---|---|
| baserequired | int | the number to raise |
| exponentrequired | int | how many times to multiply it by itself, zero or more |
print("kb", pow(2, 10))
powMod(base: int, exponent: int, modulus: int) -> int
base to the power of exponent, wrapped by the modulus at every step — huge powers without huge numbers. Refuses a negative exponent and a modulus under 1.
| Parameter | Type | What it does |
|---|---|---|
| baserequired | int | the number to raise |
| exponentrequired | int | the power, 0 or more |
| modulusrequired | int | what to wrap by, 1 or more |
print(powMod(2, 100, 1000))
randBetween(low: int, high: int) -> int
A random number from low to high, BOTH ends included — randomBelow counts from zero; this one you aim. Refuses low above high.
| Parameter | Type | What it does |
|---|---|---|
| lowrequired | int | the smallest answer, included |
| highrequired | int | the largest answer, included |
print(randBetween(600, 900))
randomSign() -> int
Minus one or one, chosen at random — a coin flip as a number to multiply by.
print("drift", randomSign() * 3)
reverseNumber(number: int) -> int
The number with its digits reversed, the sign kept: 1234 answers 4321. Faults when the mirrored digits do not fit a whole number.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to mirror |
print(reverseNumber(1234))
root(number: int, k: int) -> int
The k-th root of a number, rounded down: root(1000, 3) is 10. Refuses a negative number and a root below 2.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number to take the root of; 0 or more |
| krequired | int | which root: 2 for square, 3 for cube; 2 or more |
print(root(1000, 3))
roundTo(value: int, step: int) -> int
The value rounded to the nearest multiple of step. roundTo(23, 10) is 20. Refuses a step of zero or less.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to round |
| steprequired | int | the multiple to round to |
print("nearest ten", roundTo(23, 10))
scale(value: int, numerator: int, denominator: int) -> int
value times numerator over denominator, worked out with room to spare so the middle step cannot overflow. The fixed-point workhorse: scale(ms, 3, 2) is half again as long. Refuses a zero denominator.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to scale |
| numeratorrequired | int | the top of the fraction to scale by |
| denominatorrequired | int | the bottom of the fraction to scale by |
print("longer", scale(600, 3, 2))
shiftLeft(n: int, places: int) -> int
The number with its bits moved left, which doubles it once per place. Refuses a shift outside 0 to 63.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to shift |
| placesrequired | int | how many bits, 0 to 63 |
print("kb", shiftLeft(1, 10))
shiftRight(n: int, places: int) -> int
The number with its bits moved right, which halves it once per place. Refuses a shift outside 0 to 63.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to shift |
| placesrequired | int | how many bits, 0 to 63 |
print("halved", shiftRight(1024, 2))
sign(n: int) -> int
Minus one for a negative number, zero for zero, one for a positive number.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to read the sign of |
if sign(0 - 4) < 0 { print("negative") }
sinScaled(degrees: int, scale: int) -> int
The sine of an angle multiplied up into a whole number: sinScaled(90, 1000) is 1000 — how trigonometry crosses into a whole-number language.
| Parameter | Type | What it does |
|---|---|---|
| degreesrequired | int | the angle, in degrees |
| scalerequired | int | what to multiply the sine by before rounding |
print(sinScaled(90, 1000))
sqrt(n: int) -> int
The whole-number square root, rounded down like distance() is. sqrt(10) is 3. For a fraction, work in tenths or hundredths with sqrtScaled-style maths. Refuses a negative number.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to take the root of, zero or more |
print("side", sqrt(144))
sumOfDigits(number: int) -> int
The digits of a number added together, the sign ignored: 1234 answers 10.
| Parameter | Type | What it does |
|---|---|---|
| numberrequired | int | the number whose digits are added |
print(sumOfDigits(1234))
sumTo(n: int) -> int
Every whole number from one to n added together. Refuses a negative n.
| Parameter | Type | What it does |
|---|---|---|
| nrequired | int | the number to add up to, zero or more |
print("triangle", sumTo(100))
unlerp(from: int, to: int, value: int) -> int
Where a value sits between two ends, as a percentage: unlerp(0, 200, 50) is 25 — the reverse of lerp. Refuses equal ends, between which nothing has a place.
| Parameter | Type | What it does |
|---|---|---|
| fromrequired | int | the end that reads as 0 |
| torequired | int | the end that reads as 100 |
| valuerequired | int | the number to place between them |
print(unlerp(0, 200, 50))
weightedMean(values: list<int>, weights: list<int>) -> int?
The average of the values with each counting its weight's worth, rounded toward zero. None when the weights add to nothing; refuses mismatched sizes and negative weights.
| Parameter | Type | What it does |
|---|---|---|
| valuesrequired | list<int> | the numbers to average |
| weightsrequired | list<int> | how much each counts, matching one for one |
print(weightedMean(range(0, 3), range(1, 4)))
wrap(value: int, low: int, high: int) -> int
The value wrapped round into the range low to high, so it never falls off either end — an index that keeps cycling. Refuses an empty range.
| Parameter | Type | What it does |
|---|---|---|
| valuerequired | int | the number to wrap |
| lowrequired | int | the low end, included |
| highrequired | int | the high end, not included |
let corner = wrap(5, 0, 4) print(corner)