Useful Resources When Learning To Code With GML

Useful Resources When Learning To Code With GML

This short tech blog is aimed at those of you have gotten GameMaker Studio 2 and have maybe dabbled with the Drag and Drop side of things but want to progress onto using the GameMaker Language (GML), or for those of you who have no experience in programming and want to dive right in but aren't quite sure where to start. We won't be giving any code examples here, but instead, we'll be giving some pointers on where to start and some general good practices, as well as a few links to people from out fabulous community who have taken the time to create tutorials to help you make the games you've always dreamed of!

So, you've got GameMaker Studio installed, what now?


Well, we'd, first of all, recommend that you open the GameMaker manual (which you can open pressing F1 in GameMaker or from the "Help" menu at the top of the IDE) and browse to the section titled GML Overview. You really should read through every one of the pages in this section, as they'll 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 it and be aware of the way the language works and the contents of this section - and the bits you don't understand will still be useful as you work through other tutorials and resources, as you'll no doubt get an "aha!" moment, when you'll remember what you read in the manual and the tutorial you're following, will suddenly all make sense.

Now, reading through the manual like that might seem a bit boring, so why not take some time to experiment with the features that it explains as you go? The manual contains code samples for most functions, but in your early days, you will learn much better and faster if you don't copy/paste these and instead type them out and experiment with the functions yourself. You can make an object asset and add it into an otherwise empty room, then add in a Create or a 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, for example, something like this to test expressions:

var a = 10;
var b = 253;
var c = 32.888;
output = (a + b) / c;

One final thing to mention about the manual is that you can instantly find help for any function you're not sure about by using the middle mouse button or pressing "F1" when 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) and the manual will pop up already on that function's own page, explaining what the function does and how it's used.


Every time you start up GameMaker Studio 2 there is a section on the Start Page where you can get access to some official tutorials made by YoYo Games:

Start Page

All of these tutorials contain text and video options to follow along with and are designed to give you a solid understanding of how GameMaker works and also show you good practices and general paradigms to follow when working with the GameMaker Language. As such, we highly recommend that you do at least one of the main ones, like Space Rocks or Breakthough. Again, you might not understand all of what your doing just yet, but it's a great way to get started, and you'll feel proud of yourself when you see the final result, knowing that you've just made a game in a short amount of time!

It's also worth checking out the Demos page too, as that shows some of the more advanced game-development concepts as well as some other simple projects that you can study and learn from. This is less guided learning, giving you the chance to experiment and also use as a comparison tool when developing your own games later on (if something in your game doesn't work, see how YoYo did it).


Once you feel a bit more confident with the language basics, you can then move on and make small test projects. For example, make an object that outputs text to the screen when the game is run. Then make this text change depending on a keypress or a button press. Why not add a sprite to the object and draw that to the screen along with the text? Wait! 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 little experimental projects like this and then building on them a bit at a time is fundamental to learning how to use GameMaker as a whole and learning the GameMaker Language specifically, and we can't stress enough how important it is to learn these basics before starting on an actual full game project.

Basic Code Example

Once you have a few test projects under your belt, the next thing you can do to advance your knowledge and skill is to make a game... But wait! Don't jump in and start making that super mega dream project just yet! Instead, take some time to remake a classic game from the past. Why do we (and so many others!) recommend this? Well, classic games had to run on older hardware with less memory and limited GPU and CPU power, and as such they were - by necessity - smaller in scope and simpler in design. However, these games still manage to be fun, have great gameplay, and they laid the foundations for so many of the games you play now. So, by revisiting the classics and trying to recreate them you will be learning the very building blocks that ALL modern games are built from, as well as learning about good general game design and learning how to use GameMaker.

You can of course choose your own classic game and have a go at replicating it, but here are some games that are worth looking at for re-creating (roughly in order of difficulty):

The great thing about recreating these classics is that not only will you learn about game design and programming, but you will also be creating a base to add on to. Actually finishing a smaller project also gives you great insight into packaging your projects in a professional way, polishing and tweaking your code, and running your finished project on different devices so you get a feel for the other platforms (different performance levels, screen size and audio capabilities considerations) - all that good stuff.

Once you complete a project like this, you can start to edit it and modify it, making it more modern and/or changing it to suit how you think it should have been made. Who knows, maybe you can adapt and change one of these games enough to be worth publishing and showing to the world!

Classic Games


An incredibly important part of learning to program is accepting that you will get it wrong and things are not going to work the first time! It's really easy to get frustrated when making a game and things don't work out for you, but it's all part of the process, and instead of being disheartened and frustrated when your code doesn't work, treat it as a challenge! Just keep in mind that it will get easier and that you have a lot of tools available to help you work out what's gone wrong.

To start with, you have the error messages that are shown when you test your project. You should learn to interpret these messages and understand what they are saying. We'll quickly outline their content here - consider this error:

GMS2 Error Report

Here, 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). Next, it tells us that it was a variable get error, which simply means that the variable shown 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 just to confirm. 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 multiple reasons why you might have coding errors, so please check the manual, as many are all explained there in detail:

It's worth quickly mentioning here that 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 read further up). Also, if you find projects are failing and you're confident your code is okay if you are running any antivirus clients, see if temporarily pausing this allows the build to immediately work. If it does, then see our Helpdesk guide on how to configure your protection software to allow GMS2 to work properly.

Finally, learn to use the Debug Mode in GameMaker. It is ideal for those issues that are not things that make the project crash or prevent it from running, but rather are 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 permit you to see in detail what is happening and also pause the game and step through all the code, checking values and variables as you go. For more information, please read the manual:

(For quick debugging of variables not getting the correct value, you can also always just litter your code temporarily with relevant debug message calls in the problem area or code to temporarily draw the value to the screen so you can see when/how it changes, and this can often be a quick method which does the job just fine.)


GameMaker Studio has a wealth of brilliant community resources for it. The extremely talented GameMaker Community create their own tutorials and guides that they regularly update and share. With that in mind, here's a section of some of the best current resources for learning GameMaker Studio 2 from the community:

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


Finally, you may want to check out this companion tech blog to help you to learn "best practices" when making your games:

And that's about it for this tech blog. Keep in mind that making games can be challenging, but it's also great fun. We hope this blog post will help you realise your full potential and get up to speed as soon as possible when starting out making your own great games.

Happy GameMaking!