Skip to content

Instantly share code, notes, and snippets.

@tinkerer-red
tinkerer-red / constructor_call.gml
Created October 5, 2024 05:24
An unfortunate way to call an arbitrary constructor dynamically.
function constructor_call_ext(_func, _args) {
static __executors = (function(){
var _struct = {};
struct_set_from_hash(_struct, 0, function(_func, _args) { return new _func( ); });
struct_set_from_hash(_struct, 1, function(_func, _args) { return new _func( _args[0] ); });
struct_set_from_hash(_struct, 2, function(_func, _args) { return new _func( _args[0], _args[1] ); });
struct_set_from_hash(_struct, 3, function(_func, _args) { return new _func( _args[0], _args[1], _args[2] ); });
struct_set_from_hash(_struct, 4, function(_func, _args) { return new _func( _args[0], _args[1], _args[2], _args[3] ); });
struct_set_from_hash(_struct, 5, function(_func, _args) { return new _func( _args[0], _args[1], _args[2], _args[3], _args[4] ); });
struct_set_from_hash(_struct, 6, function(_func, _args) { return new _func( _args[0], _args[1], _args[2], _args[3], _args[4], _args[5] ); });
@tinkerer-red
tinkerer-red / hash_of_doom.gml
Last active September 27, 2024 12:34
Hash of Doom (execute_array)
function hash_of_doom(_funcArr) {
static __executors = (function(){
var _struct = {};
struct_set_from_hash(_struct, 0, function(_funcArr) { });
struct_set_from_hash(_struct, 1, function(_funcArr) { _funcArr[0]() });
struct_set_from_hash(_struct, 2, function(_funcArr) { _funcArr[0](); _funcArr[1]() });
struct_set_from_hash(_struct, 3, function(_funcArr) { _funcArr[0](); _funcArr[1](); _funcArr[2]() });
struct_set_from_hash(_struct, 4, function(_funcArr) { _funcArr[0](); _funcArr[1](); _funcArr[2](); _funcArr[3]() });
struct_set_from_hash(_struct, 5, function(_funcArr) { _funcArr[0](); _funcArr[1](); _funcArr[2](); _funcArr[3](); _funcArr[4]() });
struct_set_from_hash(_struct, 6, function(_funcArr) { _funcArr[0](); _funcArr[1](); _funcArr[2](); _funcArr[3](); _funcArr[4](); _funcArr[5]() });
@tinkerer-red
tinkerer-red / buffer_array.gml
Created September 17, 2024 19:55
buffer_array.gml
function buffer_array(_length, _type, _value=0) constructor {
width = _width;
height = _height;
size = width*height;
type = _type;
if (type == buffer_string)
|| (type == buffer_text) {
show_error("Type can not be a sting or text", true);
}
@tinkerer-red
tinkerer-red / CompatibilityScripts.gml
Created May 31, 2024 12:47
Every compatibility script from Game Maker Studio 1. The scripts come from the "compatibility" functions provided by Game Maker Studio 2. They are provided "as is", and compiler errors may be expected.
//-------------------------------------------------------------------------------------------------------\\
// __ It looks like you're looking for advice on initialization,
// / \ / Would you like help with that?
// | |
// @ @ Tinkerer_Red has removed all of the gml_pragma( "global", *);
// | | from the functions to prevent issues importing.
// || |/ If you would like to re-enable them just un comment them!
// || ||
// |\_/| He also commented out the MacroExpansion in
// \___/ `__global_object_depths`
function draw_hq_text_ext_transformed(_x,_y,_str,_sep,_width,_xscale,_yscale,_angle) {
//this function will automatically adjust the x, y, width, scakes and sep based on what the gui was scaled to before hand
//this is a drawing function for breaking out of the rescaling the gui layer to the highest possible quality before returning
static _is_browser = (os_browser != browser_not_a_browser);
var _w, _h;
//get the gui measurements
if (_is_browser){
_w = browser_width;
//this requires camera 0 to be active in all rooms you wish to be auto scaled
#macro __SETTINGS_AUTO_SCALE true
//these settings will require Window's window resize setting to be set to true
#macro __SETTINGS_ALLOW_WINDOW_RESIZE_HORZ true
#macro __SETTINGS_ALLOW_WINDOW_RESIZE_VERT true
@tinkerer-red
tinkerer-red / Promise.gml
Last active April 24, 2024 19:43
Javescript Promises in GameMaker's GML
#macro PROMISE_MAX_TIME (1/60 * 1_000 * 1_000) * (1/16) //the max time in milli seconds to spend on the promises, default is 1/16 of frame time of a 60 fps game
enum PROMISE_STATE {
PENDING,
RESOLVED,
REJECTED,
PAUSED,
};
function __PromiseNamespace__() {
@tinkerer-red
tinkerer-red / scrCollisions.gml
Last active April 27, 2024 04:38
more collision functions
//feather ignore all
#region jsDoc
/// @func collision_circle_array()
/// @desc This function is the same as the collision_circle() function, only instead of just detecting one instance / tile map in collision at a time, it will detect multiple instances or tile maps.
/// @param {Real} x1 : The x coordinate of the center of the circle to check.
/// @param {Real} y1 : The y coordinate of the center of the circle to check.
/// @param {Real} rad : The radius (distance in pixels from its center to its edge).
/// @param {Id.TileMapElement | Asset.GMObject | Id.Instance | Constant.All | Constant.Other | Array} obj : Asset or Object Instance or Tile Map Element ID or Array An object, instance, tile map ID, keywords all/other, or array containing these items
/// @param {Bool} prec : Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
@tinkerer-red
tinkerer-red / CollisionArray.gml
Last active November 16, 2023 15:15
GML Collision Array Functions
#region jsDoc
/// @func collision_circle_array()
/// @desc This function is the same as the collision_circle() function, only instead of just detecting one instance / tile map in collision at a time, it will detect multiple instances or tile maps.
/// @param {Real} x1 : The x coordinate of the center of the circle to check.
/// @param {Real} y1 : The y coordinate of the center of the circle to check.
/// @param {Real} rad : The radius (distance in pixels from its center to its edge).
/// @param {Object} obj : Asset or Object Instance or Tile Map Element ID or Array An object, instance, tile map ID, keywords all/other, or array containing these items
/// @param {Boolean} prec : Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
/// @param {Boolean} notme : Whether the calling instance, if relevant, should be excluded (true) or not (false).
/// @param {Array} array : The array to use to store the IDs of colliding instances
@tinkerer-red
tinkerer-red / GMString.gml
Last active October 25, 2023 17:30
GMString
///feather ignore all
function GMString(_val_or_format, _arg1=undefined, _arg2=undefined, _arg3=undefined, _arg4=undefined, _arg5=undefined, _arg6=undefined, _arg7=undefined, _arg8=undefined, _arg9=undefined, _arg10=undefined, _arg11=undefined, _arg12=undefined, _arg13=undefined, _arg14=undefined, _arg15=undefined) : __GMString__() constructor{
str = string(_val_or_format, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14, _arg15);
length = string_length(str);
}
function GMStringExt(_val_or_format, _arg_array) : __GMString__() constructor{
str = string_ext(_val_or_format, _arg_array);
length = string_length(str);
}
function GMStringFormat(_val, _total, _dec) : __GMString__() constructor{