GameMaker: Beautifying/pretty-printing JSON

Partially related to an earlier blog post about minifying JSON (which I had just updated), but adressing a different problem - sometimes, rather than trying to make your JSON more compact (and, consequently, less readable), you may want to make it more readable - be that for your own debugging purposes, or not to scare players away from files that they are allowed to edit.

Take Nuclear Throne, for example. The save file is a big nested JSON structure, and, needless to say, you aren't getting around passing it through an external JSON beautifier if you want to be able to make sense of it:

With a bit of string processing, however, you can have it printed out nicely readable:

So this post is about that.

Continue reading

Converting key code to key name and vice-versa

(click to interact)Converting key code to key name and vice-versa
(mouseover/click to play GIF) Interactive demo (if JavaScript is enabled)

This is a small post about how to convert key codes to key names and/or convert key names to key codes. Comes with sample code for GameMaker and a generic version.

Mostly published because it covers majority of common and semi-common buttons.

Continue reading

GameMaker: Simplest possible custom timelines

This post is about implementing custom timelines in GameMaker.

Admittedly, timelines remain to be one of the more dated features of the software, designed for a specific purpose and kept in their original form for compatibility.

Time to time you'll see someone stopping by on forums to write a big rant about how these are a mess, do not do what they expect them to do, and should be redesigned immediately.
People will usually also argue that doing these things by yourself is too hard.

Since it is far easier than people claim, I decided to write a post about this.

Continue reading

GameMaker: Opening links in a new tab on HTML5

On some occasions you may want to open a link in a new tab a GameMaker' HTML5 game.

As simple as it may look, this presents a bit of a problem:

  • url_open opens links in the same tab.
  • url_open_ext can open links in a new tab, but triggers popup blocker.
  • clickables can open links in a new tab, but have to be repositioned manually.
    (particularly inconvenient if scaling-positioning the game for mobile browsers)
  • Adding an actual link (<a> element) into the game template allows to open links in a new tab, but requires basic understanding of JavaScript and HTML to hide/unhide dynamically.

url_open_ext is by far the most convenient of these, so let me explain why that does not work:

To prevent any page from being able to randomly open indefinitely large quantities of new tabs, the browser will automatically block attempts to open new tabs\windows unless they originate from user interaction (click event);

GameMaker handles events, and writes down new input states to later dispatch GML-level events at the right time and place (see event order). This means that your GML code inside a "Mouse Pressed" event does not count as originating from a user interaction (as it executes a few milliseconds later), and thus is not allowed to open new tabs (and do some other things).

However, with a bit of JS (and understanding of internal workings of GM), it is possible to accomplish the intended result, and this post is about that.

Continue reading