Skip to content

Instantly share code, notes, and snippets.

@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{
@tinkerer-red
tinkerer-red / string_split_by_width direct conversion.gml
Created October 19, 2023 12:44
GML : string_split_by_width()
function string_split_by_width(_str, _line_width, _font=draw_get_font()) {
if (_str == undefined) return;
if (_line_width < 0) _line_width = 10000000; // means nothing will "wrap"
var _prev_font = draw_get_font();
draw_set_font(_font);
var _whitespace = " ";
var _newline = chr(0x0a); // \n
@tinkerer-red
tinkerer-red / gist:388b323a9bd43a8555c8322cdf0f7187
Created October 12, 2023 16:06
GML implementation of `trace`
#macro trace __trace(_GMFILE_+"/"+_GMFUNCTION_+":"+string(_GMLINE_)+": ")
function __trace(_location) {
static __struct = {};
__struct.__location = _location;
return method(__struct, function(_str){
show_debug_message(__location + ": " + string(_str));
});
}
@tinkerer-red
tinkerer-red / super example.gml
Created October 12, 2023 10:25
Example of super using a self contained callstack
function log(_str) {return show_debug_message(_str)};
function A() constructor {
static example = function(){
log("Calling A");
}
}
function B() : A() constructor {
static example = function() {