Skip to content

Instantly share code, notes, and snippets.

View tabularelf's full-sized avatar
🇦🇺

TabularElf tabularelf

🇦🇺
View GitHub Profile
@tabularelf
tabularelf / listionary.gml
Last active September 11, 2023 12:10
Listionary (For converting an array of structs or struct of arrays into a list/dictionary combo, with method accessors!)
function Listionary(_object) {
static __Value = function(_pos) {
if (argument_count > 1) {
struct_set_from_hash(list[_pos], hash, argument[1]);
return;
}
return struct_get_from_hash(list[_pos], hash);
}
static __ListGet = function(_pos) {
@tabularelf
tabularelf / AtS_StA.gml
Last active September 10, 2023 17:05
array_to_struct and struct_to_array
function array_to_struct(_array) {
var _struct = {};
var _i = 0;
repeat(array_length(_array)) {
if (is_array(_array[_i]) || is_struct(_array[_i])) {
show_error("Cannot convert array or struct to key", true);
}
_struct[$ string(_array[_i])] = _array[_i];
++_i;
}
@tabularelf
tabularelf / scope rules.gml
Last active January 25, 2024 20:08
GameMaker function/method scope rules
/*
Scope Rules:
Caller == Whoever calls this method/function, is scoped to the caller. This is dependent on if there's an lvalue (lvalue.func()) or not. (for methods, the scope will be undefined).
Instance == Regardless of whoever calls this method/function, it's scoped to the instance that declared it and not the caller. (Or if using method, whatever instance that was passed in the scope that's not "undefined")
*/
// Declared in a script
// Scope == Caller, global (Will work no matter where you call it)
function myFunction() {
@tabularelf
tabularelf / function_execute.gml
Last active October 4, 2023 23:46
Executing functions or methods with an array of arguments
/// @func function_execute( function/method, [arguments_in_array])
/// @desc Executes a runtime function, GML function or method, respecting method rules.
/// @param function/method
/// @param [arguments_in_array]
function function_execute(_funcMethod, _args = undefined) {
gml_pragma("forceinline");
if (is_undefined(_args)) return _funcMethod();
var _func = _funcMethod;
var _self = self;
@tabularelf
tabularelf / igor_varriables.txt
Last active January 7, 2022 08:50
All of the variables exposed by IGOR
YYdebug - Whether you're using debugger or not
YYoutputFolder - The output folder of where your game compiled contents are stored
YYprojectDir - Project Directory
YYprojectName - Project Name
YYprojectPath - Path to your .yyp
YYruntimeLocation - The runtime location
YYSteamIDE - Is using Steam version
YYsteamOptions - Steam Options (mostly SDK)
YYconfig - What kind of Configuration you're using
YYTARGET_runtime - VM or YYC
@tabularelf
tabularelf / fpsClock.gml
Last active September 10, 2023 16:59
An alternative FPS counter that even your shaders can now impact
/* TabularElf made this!
Use case:
Insert fpsClock().tick(); within the begin step event of your game management object. (And never in a loop)
You may retrieve the FPS value by calling fpsClock() anytime to return a string value of the FPS.
*/
function __getFPSClockSingleton() {
static _clockStruct = new (function() constructor {
static __FPSMain = game_get_speed(gamespeed_fps);
@tabularelf
tabularelf / ds_to_struct_array.gml
Last active September 10, 2023 16:51
Convert ds_grid/map/list to struct/array equivalents and vice versa
/*
Created by: TabularElf. https://tabularelf.com/
Clarification: This is a set of scripts that allow you to convert ds_maps, ds_lists and ds_grids into structs/arrays and vice versa.
Addtionally, ds_maps and ds_lists will automatically convert ds_map/ds_list children into structs/arrays, and vice versa.
You can disable this by assigning the optional argument [convert_children] to false when calling the function.
Note: This does not convert any data structures that are stored within or as ds_grids and vice versa.
Also to access a cell from an array2D of a ds_grid, you will do the following.
grid[cell_x][cell_y]
*/
@tabularelf
tabularelf / function_execute.gml
Last active June 20, 2022 01:50
A way to execute runtime/gml functions and method functions with one script.
function __func_array_insert(_array) {
var _length = argument_count-2;
var _index = argument[1]-1;
var _i = 1;
array_copy(_array,_index+_length, _array, _index, _length);
repeat(_length) {
_array[@ ++_index] = argument[++_i];
}
}
@tabularelf
tabularelf / array_2d.gml
Last active June 1, 2023 01:29
Recreating GameMaker's 2D arrays, now that they're deprecated.
// Made by TabularElf
/// @func array_2d_height
/// @param 2DArray
function array_2d_height(_array) {
return array_length(_array);
}
/// @func array_2d_length
/// @param 2DArray