Mastering GML Code: Six Resources That Taught The Pros How To Code With GameMaker

Ross Bramble
18th January 2023

Learning to code a game can feel like a daunting task. Thankfully, learning to code with GameMaker is much easier than you think, thanks to our two GameMaker Languages - GML Code, and GML Visual.

Whether you're exploring the GML Visual coding system or diving straight into coding with GameMaker Language (GML), GameMaker and its community offer a range of resources to help you get up to speed.

Here are six GameMaker resources that taught the professionals how to code in GameMaker.

This article includes:

What language does GameMaker use?

GameMaker uses its very own coding language known as GameMaker Language (creative name, right?). 

GameMaker Language, or GML for short, comes in two different flavours: GML Code, and GML Visual.

GML Code allows you to write your own code and take full control of your creation. GML Visual allows you to create your own game from pre-coded building blocks.

GameMaker Language is a little different to other coding languages like Python or C#, so the resources we're about to run through are all focused specifically on how to code with GameMaker Language.

The GameMaker Manual

If you’re new to GameMaker Language (GML), the GameMaker manual is your point of truth.

You can open the GameMaker manual by pressing F1 in GameMaker, or by opening the ‘Help’ menu at the top of the IDE. You can also read the manual online whenever you’d like.

The section entitled GameMaker Language will help give you a better grip on the way GML is constructed and used. Don't worry if you don't understand all of it: the important thing is to read the tutorial and understand how the language works.

Don’t be afraid to get stuck in

Reading the GameMaker manual cover to cover won’t be for everyone. Like a hungry cook reading recipe books, eventually you’ll just want to get in the kitchen.

As you read the manual, try experimenting with the features it outlines. Reading the theory behind coding with GML will lay the foundation of your knowledge, but you won’t start to really understand how it all works until you get stuck in.

The manual contains code samples for most functions, but in your early days, you’ll learn much faster if you type them out and experiment with the functions yourself, rather than copying and pasting them.

Use the manual to make an object asset and add it into an otherwise empty room; add a Create or Step event into your object and test snippets of code dealing with Assignments, Expressions, Scope, Data Types, etc.

The code doesn’t have to be complex, either. You could use something like this to test player input:
if (keyboard_check_pressed(vk_up))
    show_message("Up key hit!");
else if (keyboard_check_pressed(vk_down))
    show_message("Down key hit!");

GameMaker manual shortcut

If you run into a function you’re not sure about, you can instantly bring up the relevant page in the manual by clicking on it with the middle mouse button, or by pressing the F1 key in the code editor.

For example, if you want to know more about the function point_direction(), simply move the cursor to it and press F1 (or put the mouse over it and click the middle mouse button). The manual will pop up already on that function's page, describing what the function does and how it's used.

Discover Functions Fast

GameMaker’s code completion makes it faster to write code and discover functions.

If you want to know everything you can do with instances, start typing instance_ and see a list of relevant functions pop up:
Discovering relevant functions in GameMaker

All instance functions and built-in variables are displayed, along with the arguments that the functions take. You can select a function or variable from the list, and then middle-click on it (or press F1) to read about it in the manual.

Similarly, discover functions for sprites, layers, collisions, or anything else you are currently working on, without ever leaving your code editor!


Discovering functions in the GameMaker Code Editor

GameMaker tutorials

Whenever you visit our website or start-up GameMaker, you’ll be able to access our official GML coding tutorials:


Where to find Tutorials on the GameMaker Start Page

These GML tutorials contain text and video options to follow along with and are designed to give you a solid understanding of how GameMaker works. They’ll also introduce best practices to follow when coding with GameMaker Language.

We highly recommend that you complete at least one of the following GML tutorials:

Again, you might not understand everything you're doing just yet, but it's a great way to get started, and the feeling of pride upon completing your first game in such a short span of time is one you’ll never forget.

GameMaker Coaching webinars

GameMaker Coaching is a regular webinar series, hosted by GameMaker Language experts such as Aaron Craig, Josia Ronancio, and Peter Morgan.

Each webinar covers a different aspect of coding with GameMaker, and offers you the chance to put your questions directly to the experts.

If you’d like to attend a live webinar, follow us on Facebook and Twitter for all the latest information.

We also upload the webinars to our YouTube channel for you to watch back whenever you’d like.

Create projects in GameMaker

Once you feel more confident with the basics of GameMaker Language, it’s time to start making your own small test projects.

For example: make an object that outputs text to the screen when the game is run, then make the text change depending on a key or button press.

Why not add a sprite to the object and draw that to the screen along with the text? Even better, why not make the sprite move when a key is pressed? Or make it move towards the mouse cursor when the mouse button is held down?

Making experimental projects like this is fundamental to learning how to use GameMaker Language.

Basic GML Code Example
SCR input code in GameMaker

Create your own game

Once you have a few test projects under your belt, it’s time to make your own game.

But patience, young Padawan: don’t jump straight into making that dream project that inspired you to learn to code in the first place. Instead, start out by recreating a classic like Galaga or Breakout.

Why do we (and so many others) recommend this? Classic 2D games had to run on older hardware with less memory and limited GPU and CPU power, making them smaller in scope and simpler in design.

In spite of the hardware limitations, these games were still fun titles with intoxicating gameplay and engaging art styles, and laid the foundations for the 2D games we still play today.

By revisiting the classics and trying to recreate them, you’ll be learning the building blocks that all modern 2D games are built from, the fundamentals of good game design, and learning how to use GameMaker.

Here are some classic games that are worth recreating, roughly in order of difficulty:

Consider remaking these classic games in GameMaker
Recreate a classic arcade title in GameMaker

Finishing a smaller project like this gives you great insight into packaging your projects in a professional way, polishing and tweaking your code, running your finished project on different devices, and optimising them for other platforms (different performance levels, screen size, and audio capability considerations etc.).

Once you complete a project, you can start to modify it and offer your own unique take. Who knows, maybe your adapted version will outstrip the originals, and be worth publishing for the world to enjoy?

Unless it’s a Nintendo property, anyway. Please don’t get yourselves sued, folks.

Learn to fail

A wise man (or whatever species Yoda is meant to be) once said, “The greatest teacher, failure is”, and that couldn’t be more true when it comes to learning to code.

An incredibly important part of learning to program with GML is accepting that you will get it wrong, and your code won’t always work as you expected. Instead of being disheartened and frustrated, treat it as a challenge.

Failure is one of your greatest resources because by fixing what went wrong, you’ll learn lessons you’ll remember for a lifetime.

Whatever goes wrong, you’ll always have the GameMaker manual, tutorials, and the GameMaker Community Forum available to help you understand how to fix it.

Error messages in GameMaker

To start with, you have the error messages that are shown when you test your project. You’ll quickly learn to interpret these messages and understand what they’re saying.

Let’s consider this error:

Error message in GameMaker

The first lines tell us the event that the error happens in (the Create Event) and the object that the event is in (the object objInit).

The error description says that the variable shown (player_name, in objInit) hasn't actually been defined at the time the code is trying to access it. Finally, it gives you the code editor line number that the error occurs on, as well as a snippet of that line of code.

Note that the line number isn't always 100% accurate on every platform, due to the way the runner compiles the game, but it should be close enough to find the error with the other information given.

You may also find that the game won't even run due to compiler errors. These will give errors in the IDE and also in your compiler log, which will allow you to track down the issue in the vast majority of cases.

However, there are various reasons why you might have coding errors, so please check the Compiler Errors section of the manual for more detail.

You should read the whole of your compiler log when looking for error messages ("Build Failed" is not your error, it's an end result, so you’d need to read further up).

Also, if you find projects are failing and you're confident your code is okay, check your antivirus. If you’re running any antivirus clients, see if temporarily pausing them allows the build to immediately work. If it does, we’ve created a Helpdesk guide on how to configure your protection software to allow GameMaker to work properly for further support.

Debug mode

Finally, learn to use the Debug Mode in GameMaker. It’s ideal for issues that don’t make the project crash or prevent it from running, but things that simply don't work as you want or expect.

Running your game in debug mode will open a new set of windows in the IDE which allows you to pause the game, step through all the code, and see in detail what’s happening, checking values and variables as you go.

Debug mode in GameMaker

For more information, see the debugger section of the manual.

For quick debugging of variables not getting the correct value, you can always just litter your code with relevant debug message calls in the relevant area of code to temporarily write the value to the output log so you can see when/how it changes.

GameMaker Community resources

GameMaker has a wealth of brilliant community resources to support you as you learn to code with GML.

The extremely talented GameMaker Community create their own tutorials and guides that they regularly update and share, including:

The following are slightly more advanced tutorials, but as you progress, you'll find the information they contain invaluable:

Practice makes perfect

With all of these GameMaker resources by your side, the only thing left to do is practise. The more you code with GameMaker Language, the better you’ll get.

You’ll also want to read up on GML best practices, which will help you manage your workspace in the most efficient way possible.

Making games can be challenging, but it's also great fun. Take advantage of the GameMaker resources we’ve outlined above, and one day, it could be your game making the headlines.

Happy GameMaking!

Written by Ross Bramble
As GameMaker's resident gaming historian, Ross Bramble brings over a decade of writing experience to managing our blog and producing our gaming articles. In his spare time, he likes to complain about how long it's been since we last saw a new Kid Icarus game.
Back to blogs