Miscellaneous Functions

The miscellaneous functions do not fit into any other category. They are used for various purposes, such as debugging, math, and others. This is the biggest category in Crust, and it contains a lot of functions. Here is a list of all the miscellaneous functions in Crust:

  • args(): Returns the command line arguments passed to the program.
  • print(values...): Prints the given values to the console. Can take multiple values, separated by commas.
  • print_raw(values...): Prints the given values to the console without the automatic newline at the end and the name of the sprite. Can take multiple values, separated by commas.
  • input(prompt): Prompts the user for input and returns the input as a string. The prompt is displayed in the console.
  • time(): Returns the current time in seconds since the program started.
  • abs(num): Returns the absolute value of the given number.
  • sqrt(num): Returns the square root of the given number.
  • sin(num): Returns the sine of the given number (in radians).
  • cos(num): Returns the cosine of the given number (in radians).
  • tan(num): Returns the tangent of the given number (in radians).
  • asin(num): Returns the arcsine of the given number (in radians).
  • acos(num): Returns the arccosine of the given number (in radians).
  • atan(num): Returns the arctangent of the given number (in radians).
  • lerp(a, b, t): Returns the linear interpolation between a and b at t, where t is a value between 0 and 1.
  • property_of(sprite, property): Returns the value of the given property of the sprite. The property can be the following:
    • name: The name of the sprite. (Not sure why anyone would use this, but it's here.)
    • x: The x-coordinate of the sprite.
    • y: The y-coordinate of the sprite.
    • size: The size of the sprite, which is a list [width, height].
    • scale: The scale of the sprite, which is a number where 1.0 is 100% scale.
    • direction: The direction of the sprite in degrees.
    • completed_broadcasts: A list of broadcast IDs that have been completed by the sprite.
    • tags: A list of tags that the sprite is in.
  • to_rad(deg): Converts the given angle in degrees to radians.
  • to_deg(rad): Converts the given angle in radians to degrees.
  • set_cam(): Sets the camera's 0, 0 position to the sprite's current position.
  • set_cam(x, y): Sets the camera's 0, 0 position to the given coordinates (x, y).
  • set_cam(x, y, zoom_x, zoom_y): Sets the camera's 0, 0 position to the given coordinates (x, y) and sets the zoom level to (zoom_x, zoom_y). The zoom level is a number where 100 is 100% zoom.
  • set_cam(x, y, zoom_x, zoom_y, rotation): Sets the camera's 0, 0 position to the given coordinates (x, y), sets the zoom level to (zoom_x, zoom_y), and sets the rotation of the camera in degrees.
  • clamp(value, min, max): Clamps the given value between the minimum and maximum values.
  • len(list | string): Returns the length of the given list or string.
  • keys(object): Returns a list of keys in the given object.
  • values(object): Returns a list of values in the given object.
  • random(min, max): Returns a random number between the given minimum and maximum values.
  • distance(x1, y1, x2, y2): Returns the distance between the two points (x1, y1) and (x2, y2).
  • distance_to(x, y): Returns the distance from the sprite to the point (x, y).
  • distance_to(spritename | "mouse"): Returns the distance from the sprite to the other sprite or the mouse.
  • write(content): Exports the given content to a file. The file is created in a the exports directory in the project root.
  • write(content, path): Exports the given content to a file at the specified path. The path is relative to the project root.
  • read(path): Imports a Crust file at the specified path. The path is relative to the project root.
  • read_binary(path): Imports a binary file at the specified path. The path is relative to the project root.
  • parse_image(binary): Parses the given binary data as an image and returns a list [width, height, pixels]. The pixels are a list of RGBA values in the format [r, g, b, a].
  • set_uv(u, v, w, x): Sets the UV coordinates for the sprite, where uv is bottom-left and wx is top-right. Can be used for atlases where theres no need for extra costumes.
  • screenshot(): Takes a screenshot of the current screen and saves it to the exports directory in the project root.
  • screenshot(path): Takes a screenshot of the current screen and saves it to the specified path. The path is relative to the project root.
  • typeof(value): Returns the type of the given value as a string.
  • push(list, value): Pushes the given value to the end of the list and returns the new list.
  • pop(list): Pops the last value from the list and returns a list containing the new list and the popped value.
  • insert(list, index, value): Inserts the given value at the specified index in the list and returns the new list.
  • insert(object, key, value): Inserts the given key-value pair into the object and returns the new object.
  • remove(list, index): Removes the value at the specified index from the list and returns a list containing the new list and the removed value.
  • extend(list1, list2): Extends the first list with the second list and returns the new list.
  • contains(list, value): Returns true if the list contains the given value, false otherwise.
  • contains(object, key): Returns true if the object contains the given key, false otherwise.
  • sort(list, closure): Sorts the list using the given closure as the comparison function. The closure should take two arguments and return a boolean.
  • filter(list, closure): Filters the list using the given closure. The closure should take one argument and return a boolean.
  • map(list, closure): Iterates over the list and applies the given closure to each element, returning a new list with the results. The closure should take one argument and return a value.
  • split(string, delimiter): Splits the given string by the specified delimiter and returns a list of substrings.
  • join(list, delimiter): Joins the elements of the list into a single string, separated by the specified delimiter.
  • starts_with(string, prefix): Returns true if the given string starts with the specified prefix, false otherwise.
  • ends_with(string, suffix): Returns true if the given string ends with the specified suffix, false otherwise.
  • trim(string): Trims the whitespace from the beginning and end of the given string and returns the trimmed string.
  • range(end): Returns a list of numbers from 0 to end - 1.
  • range(start, end): Returns a list of numbers from start to end - 1.
  • range(start, end, step): Returns a list of numbers from start to end - 1, incrementing by step.
  • to_string(value): Converts the given value to a string.
  • to_string(number, base): Converts the given decimal number to a string in the specified base (2 to 36).
  • to_number(value): Converts the given value to a number.
  • to_boolean(value): Converts the given value to a boolean.
  • to_list(value): Converts the given value to a list.
  • to_object(value): Converts the given value to an object.
  • whoami(): Returns the name of the current sprite. Works for clones as well.
  • clone_id(): Returns the ID of the current clone. Returns 0 if the sprite is not a clone.
  • frame(): Returns the current frame number. Starts at 0.
  • delta_time(): Returns the time in seconds since the last frame. Can be used to calculate the frame rate or to create smooth animations.