Home

Awesome

GameMaker Studio 2 Mathematical Scripts

<a href="https://adam-rumpf.itch.io/gamemaker-studio-2-mathematical-scripts"><img src="https://img.shields.io/badge/download-itch.io-fa5c5c?style=plastic&logo=itch.io&logoColor=white" alt="itch.io page"/></a> <a href="https://github.com/adam-rumpf/game-maker-scripts/search?l=game-maker-language"><img src="https://img.shields.io/badge/language-gml-blue?style=plastic"/></a> <a href="https://github.com/adam-rumpf/game-maker-scripts/releases"><img src="https://img.shields.io/github/v/release/adam-rumpf/game-maker-scripts?style=plastic"/></a> <a href="https://github.com/adam-rumpf/game-maker-scripts/blob/master/LICENSE"><img src="https://img.shields.io/github/license/adam-rumpf/game-maker-scripts?style=plastic"/></a> <a href="https://github.com/adam-rumpf/game-maker-scripts/commits/master"><img src="https://img.shields.io/maintenance/yes/2021?style=plastic"/></a>

A collection of general utility and mathematical objects and functions for GameMaker Studio 2 (Version 2.3). These mostly consist of utilities that I have found useful during my own game development, and I expect to periodically add more over time.

A local asset package containing all scripts can be found on the releases or from my itch.io page. I encourage you to download it, use it in your own projects, and modify the source code as much as you like.

Each script defines a single function. Most functions are standalone and are meant to be taken à la carte, but some of the more mathematically complicated functions depend on other scripts, indicated in a @requires tag.

All function names begin with an underscore (_) in order to distinguish them from built-in functions. All object names begin with the obj_ prefix. Some include methods, which are always defined in the object's Create event.

The following is a brief description of the included functions, divided into rough categories.

Categories

Number Theory Functions

A variety of scripts dealing with sequences, functions, and sets, which may have some uses for managing data structures. For example, the various pairing and inverse pairing functions can be used to store pairs of numbers as single numbers in data structures (like stacks and queues) and then recovered.

Array Functions

Common array functions (such as searching and counting).

Computational Mathematics Functions

Numerical algorithms for computational mathematics, including things like root finding and interpolation.

Linear Algebra Functions

Common linear algebra algorithms for dealing with matrices and vectors. In all functions, vectors are considered to be 1D arrays while matrices are 2D arrays (i.e. arrays of arrays).

Random Functions

Functions which involve randomization.

Cellular Automata Functions

Functions for cellular automata (CA) models. Most models are defined using a Wolfram code, an integer index that uniquely defines all possible input/output pairs for a given state space. Wolfram codes are generally indexed to correspond to a descending sequence of k-tuples, which can be generated using the _k_tuples function from the Number Theory Functions section.

Graph Objects and Functions

Objects and functions for representing graphs and networks (as abstract data structures on the "Instances" layer). The graph objects are meant to act as abstract data structures, and so are included in the scripts/graph group alongside the graph functions.

Three main objects, obj_graph, obj_vertex, and obj_edge are defined to represent a graph, its vertices, and its edges, respectively. The main graph object consists mostly of a vertex array and an edge array, but also defines some methods for common graph algorithms (like finding shortest paths). Graphs can technically be defined manually, but it is recommended to instead make use of the included _create_graph function, which automatically defines all necessary objects from an adjacency list representation and returns the resulting graph object.

It is assumed that all vertices and edges belong to only one graph. Edges are directed, so if you would like for connections to be bidirectional, you must include one edge in each direction.

File Handling

Functions for handling files, to cover some basic tasks that aren't built into GameMaker Studio.