Skip to content
Vadim Dyachenko edited this page Jan 29, 2021 · 11 revisions

Better workflow:

Syntax extensions:

Customization:

User-created:

Other:

Clone this wiki locally

Welcome to the GMEdit wiki!

Check out the sidebar on the right side for a categorized view.

Here's a small breakdown of additional language features that GMEdit offers on top of GML:

Feature name
What you can do Instead of what
#args (argument shorthand for pre-2.3)
#args a, b
// optional arguments:
#args a, b = 4, ?c
 
 
var a = argument0, b = argument1;
// optional arguments:
var a = argument[0];
var b = argument_count > 1
    ? argument[1] : 4;
var c = argument_count > 2
    ? argument[2] : undefined;
Null-conditional operators (??, ?., ?[)
var h = instance_nearest(x, y, obj_enemy)
    ?.cur_health ?? 0;
// (split into two lines to fit GitHub)
var e = instance_nearest(x, y, obj_enemy);
var h = e != noone ? e.cur_health : 0;
 
Null-conditional assignment (??=)
a ??= b;
if (a == undefined) a = b;
Template strings (with expression insertion)
draw_text(5, 5, `health: $hp/$maxhp`);
 
draw_text(5, 5, my_script(
    "health: %/%", hp, maxhp));
#import (aliases / packages)
#import variable_instance_get as v_get
var v=v_get(id,"x");
// multiple items:
#import scr_some_package.* as Pkg
Pkg.one(1);
return Pkg.two(2);
// [transformed to in saved file]
var v=variable_instance_get(id,"x");
// multiple items:

scr_some_package_one(1);
return scr_some_package_two(2);
Typed local variables (method shorthand)
var v:Grid = new Grid(4, 4);
v.set(0, 0, "hi");
var r = v.get(0, 0);

enum Some { one, two, sizeof }
var v:Some = Some();
v.one = 1;
r = v.two;
var v = ds_grid_create(4, 4);
ds_grid_set(v, 0, 0, "hi");
var r = ds_grid_get(v, 0, 0);

enum Some { one, two, sizeof }
var v = array_create(Some.sizeof);
v[@Some.one] = 1;
r = v[Some.two];
inline functions (pre-2.3)
on_click = #lambda { trace("hi!"); }
on_destroy = #lambda { trace("bye!"); }
 
 
 
 
on_click = scr_obj_test_on_click;
on_destroy = scr_obj_test_on_destroy;
// ... in scr_obj_test_on_click:
trace("hi!");
// ... in scr_obj_test_on_destroy:
trace("bye!");
#mfunc (macros with arguments)
#mfunc swap(a, b) { var _z=a;a=b;b=_z;}
var a = "1", b = "2";
show_debug_message(a + " " + b); // 1 2
swap(a, b);
show_debug_message(a + " " + b); // 2 1
Scripts or manual insertion,
depending on the macro.
coroutines (scripts that can be suspended/resumed)
/// array_foreach(array)
#gmcr
var arr = argument0;
var len = array_length_1d(arr);
for (var i = 0; i < len; i++) {
    yield arr[i];
}

// used like:
var iter = array_foreach(0, myarray);
while (array_foreach(iter)) {
    show_debug_message(iter[0]);
}
For practical reasons,
you wouldn't do this to yourself