Skip to content
Vadim Dyachenko edited this page Jun 14, 2018 · 1 revision

GMLive.js is a tool for testing snippets of GML code right in a browser.

The way it works is that it compiles GML code to JS much like GameMaker itself does, and then links it to GM's HTML5 runtime. This allows the generated code to use the built-in functions and be called accordingly.

Since recently, it also uses a GMEdit-based user interface, which helps a few things.

Additional syntax

GMLive-web's syntax largely matches that of GMS, with a few additions:

Object literals

You can use JS-style lightweight objects,

var pair = { a: 1, b: 2 };
trace(pair.a);

Script declarations:

Code tabs can contain scripts. Scripts are declared much akin to how they are for GML extensions,

#define script1
// script1 code...
#define script2
// script2 code...

You can also include argument names:

#define add(a, b)
return a + b;

which would be equivalent of

#define add
return argument0 + argument1;

in regular GML.

Several scripts get called by the runtime if defined:

  • step: called from a Step event.

  • draw: called from a Draw event.

  • draw_gui: called from a Draw GUI event.

  • http: called from Async HTTP event (mind the cross-domain rules though)

  • main: called on game start/reload.

    Primarily left in for compatibility because any code before the first script declaration executes on game start now.

Accessor chaining

You can do

var a = ["a", ["b"]];
trace(a[1][0]); // "b"

without assigning values into intermediate variables.

Debugging

You can use a JS-style

debugger;

statement in your code to trigger a breakpoint and use development tools in your browser to debug the game code.

Other additions

trace(...)

Essentially a variable-argument-count version of show_debug_message with a few bells and whistles on top.

Data URIs

Data URI scheme is supported for most I/O related functions, meaning that you can embed assets as base64 if you want to.

PointerLock

Should you need mouselock for experiments, the PointerLock extension is included automatically and you can use it's functions as needed.

Differences from regular GML

Array behaviour

Arrays are create-on-write, but not copy-on-write, so passing an array to a different place and modifying it will modify the original array instead of making a copy of it.

GMEdit notes

  • Coroutine scripts must reside in separate tabs because the preprocessor works with an entire "file".
  • Ctrl+Enter and F5 are bound to run/reload.