Skip to content

Latest commit

 

History

History
1102 lines (1102 loc) · 23.2 KB

builtins.md

File metadata and controls

1102 lines (1102 loc) · 23.2 KB

List of Built-in functions

$.abs

Description:

Calculates the absolute value of a number

Example:

$.assert($.abs(-100) == 100)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.acos

Description:

Calculates the arccos of a number

Example:

$.acos(-1)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.acosh

Description:

Calculates the arccosh of a number

Example:

$.acosh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.add

Description:

Adds a Geometry Dash object or trigger to the target level

Example:

extract obj_props
$.add(obj {
    OBJ_ID: 1,
    X: 45,
    Y: 45,
})

Allowed by default: yes

Arguments:

The object or trigger to add

$.append

Description:

Appends a value to the end of an array. You can also use array.push(value)

Example:

let arr = []
$.append(arr, 1)
$.assert(arr == [1])

Allowed by default: yes

Arguments:

# Name Type
1 arr mutable Array
2 val

$.asin

Description:

Calculates the arcsin of a number

Example:

$.asin(1)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.asinh

Description:

Calculates the arcsinh of a number

Example:

$.asinh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.assert

Description:

Throws an error if the argument is not true

Example:

$.assert(true)

Allowed by default: yes

Arguments:

# Name Type
1 b Bool

$.atan

Description:

Calculates the arctan of a number

Example:

$.atan(1)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.atan2

Description:

Calculates the arctan^2 of a number

Example:

$.atan2(a, b)

Allowed by default: yes

Arguments:

# Name Type
1 x Number
2 y Number

$.atanh

Description:

Calculates the arctanh of a number

Example:

$.atanh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.b64decode

Description:

Returns the input string decoded from base64 encoding (useful for text objects)

Example:

$.b64decode("aGVsbG8gdGhlcmU=")

Allowed by default: yes

Arguments:

# Name Type
1 s Str

$.b64encode

Description:

Returns the input string encoded with base64 encoding (useful for text objects)

Example:

$.b64encode("hello there")

Allowed by default: yes

Arguments:

# Name Type
1 s Str

$.cbrt

Description:

Calculates the cube root of a number

Example:

$.assert($.cbrt(27) == 3)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.ceil

Description:

Calculates the ceil of a number, AKA the number rounded up to the nearest integer

Example:

$.assert($.ceil(1.5) == 2)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.cos

Description:

Calculates the cos of an angle in radians

Example:

$.cos(3.1415)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.cosh

Description:

Calculates the cosh of a number

Example:

$.cosh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.display

Description:

returns the value display string for the given value

Example:

$.display(counter()) // "counter(?i, bits = 16)"

Allowed by default: yes

Arguments:

# Name Type
1 a

$.edit_obj

Description:

Changes the value of an object key. You can also use object.set(key, value)

Example:

$.edit_obj(object, ROTATION, 180)

Allowed by default: yes

Arguments:

# Name Type
1 o, m mutable Obj
2 key
3 value

$.exp

Description:

Calculates the e^x of a number

Example:

$.exp(x)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.exp2

Description:

Calculates the 2^x of a number

Example:

$.assert($.exp2(10) == 1024)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.exp_m1

Description:

Calculates e^x - 1 in a way that is accurate even if the number is close to zero

Example:

$.exp_m1(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.extend_trigger_func

Description:

Executes a macro in a specific trigger function context

Example:

$.extend_trigger_func(10g, () {
    11g.move(10, 0, 0.5) // will add a move trigger in group 10
})

Allowed by default: yes

Arguments:

# Name Type
1 group
2 mac Macro

$.floor

Description:

Calculates the floor of a number, AKA the number rounded down to the nearest integer

Example:

$.assert($.floor(1.5) == 1)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.fract

Description:

Gets the fractional part of a number

Example:

$.assert($.fract(123.456) == 0.456)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.get_input

Description:

Gets some input from the user

Example:

inp = $.get_input()

Allowed by default: yes

Arguments:

# Name Type
1 prompt Str

$.http_request

Description:

Sends a HTTP request

Allowed by default: no

Arguments:

# Name Type
1 method Str
2 url Str
3 headers Dict
4 body Str

$.hypot

Description:

Calculates the hypothenuse in a right triangle with sides a and b

Example:

$.assert($.hypot(3, 4) == 5) // because 3^2 + 4^2 = 5^2

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$.ln

Description:

Calculates the ln (natural log) of a number

Example:

$.ln(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.log

Description:

Calculates the log base x of a number

Example:

$.log(num, base)

Allowed by default: yes

Arguments:

# Name Type
1 n Number
2 base Number

$.matches

Description:

Returns true if the value matches the pattern, otherwise it returns false

Example:

$.matches([1, 2, 3], [@number])

Allowed by default: yes

Arguments:

# Name Type
1 val
2 pattern

$.max

Description:

Calculates the max of two numbers

Example:

$.assert($.max(1, 2) == 2)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$.min

Description:

Calculates the min of two numbers

Example:

$.assert($.min(1, 2) == 1)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$.mutability

Description:

Checks if a value reference is mutable

Example:

const = 1
$.assert(!$.mutability(const))
let mut = 1
$.assert($.mutability(mut))

Allowed by default: yes

Arguments:

# Name Type
1 var

$.pop

Description:

Removes a value from the end of an array, and returns it. You can also use array.pop()

Example:

let arr = [1, 2, 3]
$.assert($.pop(arr) == 3)
$.assert(arr == [1, 2])

Allowed by default: yes

Arguments:

# Name Type
1 arr mutable

$.print

Description:

Prints value(s) to the console

Example:

$.print("Hello world!")

Allowed by default: yes

Arguments:

any

$.random

Description:

Generates random numbers, or picks a random element of an array

Example:

$.random() // a completely random number
$.random([1, 2, 3, 6]) // returns either 1, 2, 3, or 6
$.random(1, 10) // returns a random integer between 1 and 10

Allowed by default: yes

Arguments:

see example

$.readfile

Description:

Returns the contents of a file in the local system

Example:

data = $.readfile("file.txt")

Allowed by default: no

Arguments:

Path of file to read, and the format it's in ("text", "bin", "json", "toml" or "yaml")

$.regex

Description:

Performs a regex operation on a string

Allowed by default: yes

Arguments:

mode can be either "match", "replace" or "findall"

# Name Type
1 regex Str
2 s Str
3 mode Str
4 replace

$.remove_index

Description:

Removes a specific value from an array. You can also use array.remove(index)

Example:

$.remove_index(names, 2)

Allowed by default: yes

Arguments:

# Name Type
1 arr mutable
2 index Number

$.round

Description:

Rounds a number

Example:

$.assert($.round(1.2) == 1)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.sin

Description:

Calculates the sin of an angle in radians

Example:

$.sin(3.1415)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.sinh

Description:

Calculates the hyperbolic sin of a number

Example:

$.sinh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.split_str

Description:

Returns an array from the split string. You can also use string.split(delimiter)

Example:

$.assert($.split_str("1,2,3", ",") == ["1", "2", "3"])

Allowed by default: yes

Arguments:

# Name Type
1 s Str
2 substr Str

$.spwn_version

Description:

Gets the current version of spwn

Example:

$.spwn_version()

Allowed by default: yes

Arguments:

none

$.sqrt

Description:

Calculates the square root of a number

Example:

$.sqrt(2)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.substr

Description:

Returns a specified part of the input string

Example:

$.substr("hello there", 1, 5)

Allowed by default: yes

Arguments:

# Name Type
1 val Str
2 start_index Number
3 end_index Number

$.tan

Description:

Calculates the tan of an angle in radians

Example:

$.tan(3.1415)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.tanh

Description:

Calculates the hyperbolic tan of a number

Example:

$.tanh(num)

Allowed by default: yes

Arguments:

# Name Type
1 n Number

$.time

Description:

Gets the current system time in seconds

Example:

now = $.time()

Allowed by default: yes

Arguments:

none

$.trigger_fn_context

Description:

Returns the start group of the current trigger function context

Example:

$.trigger_fn_context()

Allowed by default: yes

Arguments:

none

$.writefile

Description:

Writes a string to a file in the local system (any previous content will be overwritten, and a new file will be created if it does not already exist)

Example:

$.write_file("file.txt", "Hello")

Allowed by default: no

Arguments:

# Name Type
1 path Str
2 data Str

Default Implementations for Operators

$._add_

Description:

Default implementation of the += operator

Example:

$._add_(val, 10)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable
2 b

$._and_

Description:

Default implementation of the && operator

Example:

$._and_(true, true)

Allowed by default: yes

Arguments:

# Name Type
1 a Bool
2 b Bool

$._as_

Description:

Default implementation of the as operator

Example:

$._as_(1000, @string)

Allowed by default: yes

Arguments:

# Name Type
1 a
2 t TypeIndicator

$._assign_

Description:

Default implementation of the = operator

Example:

$._assign_(val, 64)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable
2 b

$._decrement_

Description:

Default implementation of the n-- operator

Example:

_decrement_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number

$._display_

Description:

returns the default value display string for the given value

Example:

$._display_(counter()) // "@counter::{ item: ?i, bits: 16 }"

Allowed by default: yes

Arguments:

# Name Type
1 a

$._divide_

Description:

Default implementation of the /= operator

Example:

$._divide_(val, 3)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number
2 b Number

$._divided_by_

Description:

Default implementation of the / operator

Example:

$._divided_by_(64, 8)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._either_

Description:

Default implementation of the | operator

Example:

$._either_(@number, @counter)

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b

$._equal_

Description:

Default implementation of the == operator

Example:

$._equal_("hello", "hello")

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b

$._exponate_

Description:

Default implementation of the ^= operator

Example:

$._exponate_(val, 3)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number
2 b Number

$._has_

Description:

Default implementation of the has operator

Example:

$._has_([1,2,3], 2)

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b

$._increment_

Description:

Default implementation of the n++ operator

Example:

$._increment_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number

$._intdivide_

Description:

Default implementation of the /%= operator

Example:

$._intdivide_(val, 3)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number
2 b Number

$._intdivided_by_

Description:

Default implementation of the /% operator

Example:

$._intdivided_by_(64, 8)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._less_or_equal_

Description:

Default implementation of the <= operator

Example:

$._less_or_equal_(100, 100)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._less_than_

Description:

Default implementation of the < operator

Example:

$._less_than_(50, 100)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._minus_

Description:

Default implementation of the - operator

Example:

$._minus_(128, 64)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._mod_

Description:

Default implementation of the % operator

Example:

$._mod_(70, 8)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._modulate_

Description:

Default implementation of the %= operator

Example:

$._modulate_(val, 3)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number
2 b Number

$._more_or_equal_

Description:

Default implementation of the >= operator

Example:

$._more_or_equal_(100, 100)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._more_than_

Description:

Default implementation of the > operator

Example:

$._more_than_(100, 50)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._multiply_

Description:

Default implementation of the *= operator

Example:

$._multiply_(val, 10)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable
2 b Number

$._negate_

Description:

Default implementation of the -n operator

Example:

$._negate_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a Number

$._not_

Description:

Default implementation of the !b operator

Example:

$._not_(b)

Allowed by default: yes

Arguments:

# Name Type
1 a Bool

$._not_equal_

Description:

Default implementation of the != operator

Example:

$._not_equal_("hello", "bye")

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b

$._or_

Description:

Default implementation of the || operator

Example:

$._or_(true, false)

Allowed by default: yes

Arguments:

# Name Type
1 a Bool
2 b Bool

$._plus_

Description:

Default implementation of the + operator

Example:

$._plus_(32, 32)

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b

$._pow_

Description:

Default implementation of the ^ operator

Example:

$._pow_(8, 2)

Allowed by default: yes

Arguments:

# Name Type
1 a Number
2 b Number

$._pre_decrement_

Description:

Default implementation of the --n operator

Example:

$._pre_decrement_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number

$._pre_increment_

Description:

Default implementation of the ++n operator

Example:

$._pre_increment_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number

$._range_

Description:

Default implementation of the .. operator

Example:

$._range_(0, 10)

Allowed by default: yes

Arguments:

# Name Type
1 val_a
2 b Number

$._subtract_

Description:

Default implementation of the -= operator

Example:

$._subtract_(val, 10)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable Number
2 b Number

$._swap_

Description:

Default implementation of the <=> operator

Example:

$._swap_(a, b)

Allowed by default: yes

Arguments:

# Name Type
1 a mutable
2 b mutable

$._times_

Description:

Default implementation of the * operator

Example:

$._times_(8, 8)

Allowed by default: yes

Arguments:

# Name Type
1 a
2 b Number

$._unary_range_

Description:

Default implementation of the ..n operator

Example:

$._unary_range_(n)

Allowed by default: yes

Arguments:

# Name Type
1 a Number