-
Notifications
You must be signed in to change notification settings - Fork 48
GMLive.js
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.
GMLive-web's syntax largely matches that of GMS, with a few additions:
You can use JS-style lightweight objects,
var pair = { a: 1, b: 2 };
trace(pair.a);
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.
You can do
var a = ["a", ["b"]];
trace(a[1][0]); // "b"
without assigning values into intermediate variables.
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.
Essentially a variable-argument-count version of show_debug_message with a few bells and whistles on top.
Data URI scheme is supported for most I/O related functions, meaning that you can embed assets as base64 if you want to.
Should you need mouselock for experiments, the PointerLock extension is included automatically and you can use it's functions as needed.
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.
- Coroutine scripts must reside in separate tabs because the preprocessor works with an entire "file".
- Ctrl+Enter and F5 are bound to run/reload.
- Smart auto-completion
- Types
- JSDoc tags (incl. additional ones)
- @hint tag (mostly 2.3)
- `vals: $v1 $v2` (template strings)
- #args (pre-2.3 named arguments)
- ??= (for pre-GM2022 optional arguments)
- ?? ?. ?[ (pre-GM2022 null-conditional operators)
- #lambda (pre-2.3 function literals)
- => (2.3+ function shorthands)
- #import (namespaces and aliases)
- v:Type (local variable types)
- #mfunc (macros with arguments)
- #gmcr (coroutines)