Skip to content

Latest commit

 

History

History
1282 lines (1282 loc) · 25.5 KB

builtins.md

File metadata and controls

1282 lines (1282 loc) · 25.5 KB

List of Built-in functions

$.abs

Description:

Calculates the absolute value of a number

Example:

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

Allowed by default: true

Arguments:

Name Type
n Number

$.acos

Description:

Calculates the arccos of a number

Example:

$.acos(-1)

Allowed by default: true

Arguments:

Name Type
n Number

$.acosh

Description:

Calculates the arccosh of a number

Example:

$.acosh(1)

Allowed by default: true

Arguments:

Name Type
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: true

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: true

Arguments:

Name Type
arr mutable Array
val

$.asin

Description:

Calculates the arcsin of a number

Example:

$.asin(1)

Allowed by default: true

Arguments:

Name Type
n Number

$.asinh

Description:

Calculates the arcsinh of a number

Example:

$.asinh(0)

Allowed by default: true

Arguments:

Name Type
n Number

$.assert

Description:

Throws an error if the argument is not true

Example:

$.assert(true)

Allowed by default: true

Arguments:

Name Type
b Bool

$.atan

Description:

Calculates the arctan of a number

Example:

$.atan(1)

Allowed by default: true

Arguments:

Name Type
n Number

$.atan2

Description:

Calculates the arctan^2 of a number

Example:

$.atan2(0, -1)

Allowed by default: true

Arguments:

Name Type
x Number
y Number

$.atanh

Description:

Calculates the arctanh of a number

Example:

$.atanh(0.996)

Allowed by default: true

Arguments:

Name Type
n Number

$.b64decode

Description:

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

Example:

$.b64decode("aGVsbG8gdGhlcmU=")

Allowed by default: true

Arguments:

Name Type
s Str

$.b64encode

Description:

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

Example:

$.b64encode("hello there")

Allowed by default: true

Arguments:

Name Type
s Str

$.cbrt

Description:

Calculates the cube root of a number

Example:

$.cbrt(27)

Allowed by default: true

Arguments:

Name Type
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: true

Arguments:

Name Type
n Number

$.cos

Description:

Calculates the cos of an angle in radians

Example:

$.cos(3.1415)

Allowed by default: true

Arguments:

Name Type
n Number

$.cosh

Description:

Calculates the cosh of a number

Example:

$.cosh(0)

Allowed by default: true

Arguments:

Name Type
n Number

$.display

Description:

returns the value display string for the given value

Example:

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

Allowed by default: true

Arguments:

Name Type
a

$.edit_obj

Description:

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

Example:


extract obj_props
let object = color_trigger(BG, 0, 0, 0, 0.5)
$.edit_obj(object, X, 600)
    

Allowed by default: true

Arguments:

Name Type
o, m mutable Obj
key
value

$.exp

Description:

Calculates the e^x of a number

Example:

$.exp(5) // e^5

Allowed by default: true

Arguments:

Name Type
n Number

$.exp2

Description:

Calculates the 2^x of a number

Example:

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

Allowed by default: true

Arguments:

Name Type
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(0.002)

Allowed by default: true

Arguments:

Name Type
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: true

Arguments:

Name Type
group
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: true

Arguments:

Name Type
n Number

$.fract

Description:

Gets the fractional part of a number

Example:

$.fract(1.23)

Allowed by default: true

Arguments:

Name Type
n Number

$.get_input

Description:

Gets some input from the user

Example:

// inp = $.get_input('What is your name?')

Allowed by default: true

Arguments:

Name Type
prompt Str

$.hash

Description:

Calculates the numerical hash of a value

Example:

$.hash("hello")

Allowed by default: true

Arguments:

Name Type
n

$.http_request

Description:

Sends an HTTP request

Example:


Allowed by default: false

Arguments:

Name Type
method Str
url Str
headers Dict
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: true

Arguments:

Name Type
a Number
b Number

$.level_objects

Description:

Returns a array of the objects in the level being written to, or an empty array if there is no output level

Example:

level = $.level_objects()

Allowed by default: true

Arguments:

$.level_string

Description:

Returns the level string of the level being written to, or nothing if there is no output level

Example:

level_string = $.level_string()

Allowed by default: true

Arguments:

$.ln

Description:

Calculates the ln (natural log) of a number

Example:

$.ln(2.71828)

Allowed by default: true

Arguments:

Name Type
n Number

$.log

Description:

Calculates the log base x of a number

Example:

$.assert($.log(1024, 2) == 10)

Allowed by default: true

Arguments:

Name Type
n Number
base Number

$.max

Description:

Calculates the max of two numbers

Example:

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

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.min

Description:

Calculates the min of two numbers

Example:

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

Allowed by default: true

Arguments:

Name Type
a Number
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: true

Arguments:

Name Type
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: true

Arguments:

Name Type
arr mutable

$.print

Description:

Prints value(s) to the console

Example:

$.print("Hello world!")

Allowed by default: true

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..11) // returns a random integer between 1 and 10
    

Allowed by default: true

Arguments:

see example

$.readfile

Description:

Returns the contents of a file in the local system (uses the current directory as base for relative paths)

Example:

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

Allowed by default: false

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

Example:


Allowed by default: true

Arguments:

mode can be either "match", "replace", "find_all" or "find_groups"

Name Type
regex Str
s Str
mode Str
replace

$.remove_index

Description:

Removes a specific value from an array, string or dictionary. You can also use array.remove(index) or dict.remove(key)

Example:


let names = ['James', 'Sophia', 'Romulus', 'Remus', 'Tiberius']
$.remove_index(names, 2)
$.assert(names == ['James', 'Sophia', 'Remus', 'Tiberius'])

let name_age = {
    'Sophia': 34, 
    'Romulus': 14, 
    'Remus': 15, 
}
$.remove_index(name_age, 'Romulus')
$.assert(name_age == {
    'Sophia': 34, 
    'Remus': 15, 
})
    

Allowed by default: true

Arguments:

Name Type
arr mutable
index

$.round

Description:

Rounds a number

Example:

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

Allowed by default: true

Arguments:

Name Type
n Number

$.sin

Description:

Calculates the sin of an angle in radians

Example:

$.sin(3.1415)

Allowed by default: true

Arguments:

Name Type
n Number

$.sinh

Description:

Calculates the hyperbolic sin of a number

Example:

$.sinh(0)

Allowed by default: true

Arguments:

Name Type
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: true

Arguments:

Name Type
s Str
substr Str

$.spwn_version

Description:

Gets the current version of spwn

Example:

$.spwn_version()

Allowed by default: true

Arguments:

none

$.sqrt

Description:

Calculates the square root of a number

Example:

$.sqrt(2)

Allowed by default: true

Arguments:

Name Type
n Number

$.substr

Description:

Returns a specified part of the input string

Example:

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

Allowed by default: true

Arguments:

Name Type
val Str
start_index Number
end_index Number

$.tan

Description:

Calculates the tan of an angle in radians

Example:

$.tan(3.1415)

Allowed by default: true

Arguments:

Name Type
n Number

$.tanh

Description:

Calculates the hyperbolic tan of a number

Example:

$.tanh(0.549)

Allowed by default: true

Arguments:

Name Type
n Number

$.time

Description:

Gets the current system time in seconds

Example:

now = $.time()

Allowed by default: true

Arguments:

none

$.trigger_fn_context

Description:

Returns the start group of the current trigger function context

Example:

$.trigger_fn_context()

Allowed by default: true

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: false

Arguments:

Name Type
path Str
data Str

Default Implementations for Operators

$.add

Description:

Default implementation of the += operator

Example:

let val = 25
$._add_(val, 10)
$.assert(val == 35)

Allowed by default: true

Arguments:

Name Type
a mutable
b

$.and

Description:

Default implementation of the && operator

Example:

$._and_(true, true)

Allowed by default: true

Arguments:

Name Type
a Bool
b Bool

$.as

Description:

Default implementation of the as operator

Example:

$._as_(1000, @string)

Allowed by default: true

Arguments:

Name Type
a
t TypeIndicator

$.assign

Description:

Default implementation of the = operator

Example:

let val = 0
$._assign_(val, 64)
$.assert(val == 64)

Allowed by default: true

Arguments:

Name Type
a mutable
b

$.both

Description:

Default implementation of the & operator

Example:

$._both_(@number, @counter)

Allowed by default: true

Arguments:

Name Type
a
b

$.decrement

Description:

Default implementation of the n-- operator

Example:

let n = 1
$._decrement_(n)
$.assert(n == 0)

Allowed by default: true

Arguments:

Name Type
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: true

Arguments:

Name Type
a

$.divide

Description:

Default implementation of the /= operator

Example:

let val = 9
$._divide_(val, 3)
$.assert(val == 3)

Allowed by default: true

Arguments:

Name Type
a mutable Number
b Number

$.divided_by

Description:

Default implementation of the / operator

Example:

$._divided_by_(64, 8)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.either

Description:

Default implementation of the | operator

Example:

$._either_(@number, @counter)

Allowed by default: true

Arguments:

Name Type
a
b

$.eq_pattern

Description:

Default implementation of the ==a operator

Example:

$.assert(10 is $._eq_pattern_(10))

Allowed by default: true

Arguments:

Name Type
a

$.equal

Description:

Default implementation of the == operator

Example:

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

Allowed by default: true

Arguments:

Name Type
a
b

$.exponate

Description:

Default implementation of the ^= operator

Example:

let val = 3
$._exponate_(val, 3)
$.assert(val == 27)

Allowed by default: true

Arguments:

Name Type
a mutable Number
b Number

$.in

Description:

Default implementation of the in operator

Example:

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

Allowed by default: true

Arguments:

Name Type
a
b

$.in_pattern

Description:

Default implementation of the in a operator

Example:

$.assert(10 is $._in_pattern_([8, 10, 12]))

Allowed by default: true

Arguments:

Name Type
a

$.increment

Description:

Default implementation of the n++ operator

Example:

let n = 0
$._increment_(n)
$.assert(n == 1)

Allowed by default: true

Arguments:

Name Type
a mutable Number

$.intdivide

Description:

Default implementation of the /%= operator

Example:

let val = 10
$._intdivide_(val, 3)
$.assert(val == 3)

Allowed by default: true

Arguments:

Name Type
a mutable Number
b Number

$.intdivided_by

Description:

Default implementation of the /% operator

Example:

$._intdivided_by_(64, 8)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.is

Description:

Default implementation of the is operator

Example:

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

Allowed by default: true

Arguments:

Name Type
val
pattern

$.less_or_eq_pattern

Description:

Default implementation of the <=a operator

Example:

$.assert(10 is $._less_or_eq_pattern_(10))

Allowed by default: true

Arguments:

Name Type
a

$.less_or_equal

Description:

Default implementation of the <= operator

Example:

$._less_or_equal_(100, 100)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.less_pattern

Description:

Default implementation of the <a operator

Example:

$.assert(10 is $._less_pattern_(11))

Allowed by default: true

Arguments:

Name Type
a

$.less_than

Description:

Default implementation of the < operator

Example:

$._less_than_(50, 100)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.minus

Description:

Default implementation of the - operator

Example:

$._minus_(128, 64)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.mod

Description:

Default implementation of the % operator

Example:

$._mod_(70, 8)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.modulate

Description:

Default implementation of the %= operator

Example:

let val = 10
$._modulate_(val, 3)
$.assert(val == 1)

Allowed by default: true

Arguments:

Name Type
a mutable Number
b Number

$.more_or_eq_pattern

Description:

Default implementation of the >=a operator

Example:

$.assert(10 is $._more_or_eq_pattern_(10))

Allowed by default: true

Arguments:

Name Type
a

$.more_or_equal

Description:

Default implementation of the >= operator

Example:

$._more_or_equal_(100, 100)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.more_pattern

Description:

Default implementation of the >a operator

Example:

$.assert(10 is $._more_pattern_(9))

Allowed by default: true

Arguments:

Name Type
a

$.more_than

Description:

Default implementation of the > operator

Example:

$._more_than_(100, 50)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.multiply

Description:

Default implementation of the *= operator

Example:

let val = 5
$._multiply_(val, 10)
$.assert(val == 50)

Allowed by default: true

Arguments:

Name Type
a mutable
b Number

$.negate

Description:

Default implementation of the -n operator

Example:

$.assert($._negate_(1) == -1)

Allowed by default: true

Arguments:

Name Type
a Number

$.not

Description:

Default implementation of the !b operator

Example:

$.assert($._not_(false))

Allowed by default: true

Arguments:

Name Type
a

$.not_eq_pattern

Description:

Default implementation of the !=a operator

Example:

$.assert(10 is $._not_eq_pattern_(5))

Allowed by default: true

Arguments:

Name Type
a

$.not_equal

Description:

Default implementation of the != operator

Example:

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

Allowed by default: true

Arguments:

Name Type
a
b

$.or

Description:

Default implementation of the || operator

Example:

$._or_(true, false)

Allowed by default: true

Arguments:

Name Type
a Bool
b Bool

$.plus

Description:

Default implementation of the + operator

Example:

$._plus_(32, 32)

Allowed by default: true

Arguments:

Name Type
a
b

$.pow

Description:

Default implementation of the ^ operator

Example:

$._pow_(8, 2)

Allowed by default: true

Arguments:

Name Type
a Number
b Number

$.pre_decrement

Description:

Default implementation of the --n operator

Example:

let n = 1
$.assert($._pre_decrement_(n) == 0)

Allowed by default: true

Arguments:

Name Type
a mutable Number

$.pre_increment

Description:

Default implementation of the ++n operator

Example:

let n = 0
$.assert($._pre_increment_(n) == 1)

Allowed by default: true

Arguments:

Name Type
a mutable Number

$.range

Description:

Default implementation of the .. operator

Example:

$._range_(0, 10)

Allowed by default: true

Arguments:

Name Type
val_a
b Number

$.subtract

Description:

Default implementation of the -= operator

Example:

let val = 25
$._subtract_(val, 10)
$.assert(val == 15)

Allowed by default: true

Arguments:

Name Type
a mutable Number
b Number

$.swap

Description:

Default implementation of the <=> operator

Example:

let a = 10
let b = 5
$._swap_(a, b)
$.assert(a == 5)
$.assert(b == 10)

Allowed by default: true

Arguments:

Name Type
a mutable
b mutable

$.times

Description:

Default implementation of the * operator

Example:

$._times_(8, 8)

Allowed by default: true

Arguments:

Name Type
a
b Number