GameMaker Studio 2 Desktop

GameMaker Studio 2 Desktop

94 ratings
Hands On GameMaker: Studio 2
By TeKidder
The goal of this guide is to get you hooked on programming while learning programming concepts.

This guide focuses on developing your programming skills so that you, all by yourself, can figure out how to code cool stuff into your games or programs.
3
   
Award
Favorite
Favorited
Unfavorite
INTRO + LESSON RESOURCES
THIS GUIDE WILL BE UPDATED CONSTANTLY. IT IS NOT COMPLETE YET. I HAVE ROUGHLY 50 MORE VIDEOS THAT ARE BEING MADE DAILY AND WILL BE POSTED AS SOON AS THEY ARE AVAILABLE!


I just wanted to personally thank you for looking into this guide. I really hope it gets you understanding GameMaker: Studio 2 and excited for game development. This guide is designed to get you to be able to create any type of game all on your own without the need of a tutorial.

Other online videos and tutorials usually guide you through a single concept quickly or just get you to follow step by step ‘how-to’ instructions. Then when you go to make your own games you get stuck as soon as you want to do something slightly different from what they taught you.

This guide is different. It focuses on developing your programming skills so that you, all by yourself, can figure out how to code cool stuff into your games or programs.

I highly suggest following the videos in order and completing the challenges.

Again, thank you and happy programming!
Lesson 1 - A
Lesson

Solution Video -

Lesson 1 - B
Lesson

Solution
Lesson 1 - C
Lesson

Solution
Lesson 1 - D
Lesson

Solution
Lesson 1 - E
Lesson
Lesson 1 - F
Lesson
Lesson 2 - A
Challenge

Solution
Lesson 2.5 - A (Variables Overview)
Like any programming language GML uses variables as the basic unit for most programming operations. Variables are used to store information in the devices memory for later (or instant) use, and they are given a name so that you can refer to them in functions and programs. A variable in GML can store either a real number (like 100, 2.456575, -56 etc...) or a string (like "Hello world!").

A variable is something that we use to store a value for use in one or more operations or functions. Think of "pi", for example... it is a real world variable that holds the value 3.14159265(etc...). Why? Well, it's much easier to say to someone "pi" than "three point one four one five nine two six five"! So, naming things make life a lot simpler and it also means that should the value of that variable ever change, we don't have to change the number everywhere as the variable name is still the same. In GML a variable has a name that must start with a letter and can contain only letters, numbers, and the underscore symbol '_' with a maximum length of 64 symbols. So, valid variables are things like fish, foo_bar, num1, and invalid variables would be 6fish, foo bar, or *num. Now, In many programing languages you need to "declare" a variable before you can use it. This basically means that you tell the computer the name you wish to use so that it can assign a place in memory to store whatever value you decide to hold in that variable. With GML, that is not always necessary as it depends on the scope of the variable. There are four main variable categories when you program with GameMaker: Studio and each has its own scope (which is can be considered as its area of operation, or reach). These variables and their scope are outlined below:

instance: these are the most common variables and are defined within an instance. These are unique to that instance and can be used in any event and any function within that instance.

local: these variables must be declared using the "var" function. A local variable is only valid for the event or script resource in which it is created. So GameMaker: Studio will create the variable, use it for the duration of the event and then "forget" it again, meaning that if you try to use it later you will get an "unknown variable" error.

global: a global variable is one that belongs to the game world itself and not to any one instance. It has to be declared as global first, but after that any instance can check or change the variable and the value will always reflect the last operation done on it, no matter what instance or code box has performed the operation.

built in variables: these are special variables that are "built into" the objects and the rooms in the game world and they can be instance only or global in scope (but never local) .
Lesson 2.5 - B (Instance Variables)
An instance variable is one that's scope is limited to the instance that creates it.
An instance variable is created within an instance of an object and is considered unique to that instance - ie: many instances of the same object can have the same variable, but each variable can hold a different value as they are unique to each instance. But how is an instance variable created? Well, you create new variables simply by assigning a value to them as shown in this small example:

potions = 12;
life = 100;
name = "Jock MacSweeney";
strength = 5.5;
armour = -2;

As you can see you just have to give the name and then a value (either numeric or a string) to set that variable and have it ready for use within an instance of the object you are coding for. These variables can then be used and modified in a number of ways from within the instance, for example this code could be in a collision event and used to take an amount off of the variable "life":

life -= 5 + armour;

If "life" is at 100 it will now have a value of 97 (100 - (5 + -2) = 97). Now, that's a simple example, and you could replace "armour" for the actual value of -2, but what happens if you use that value in multiple places and then decide to change it? You would have to go through ALL your code and change every -2 to whatever the new value is, which is time consuming and very error prone! But if you use a variable, all you have to do is reassign it a new value and the code will automatically use that new value from then onwards, making things far more flexible and far easier to fix should there be a problem. It should also be noted that even if a value is not going to change it is far easier to remember what a variable called "life" means rather than just looking at a number!

GameMaker: Studio has a collection of "built in" instance variables too, so you should be aware of them as you may name one of your own instance variables the same or wish to have your own global variable with the same name and wonder why you are getting errors! They are easy to spot, however, as they are shown in a different colour in the code editor and also come up in the auto-complete bar at the bottom.
Lesson 2.5 - C (Local Variables)
A local variable is one that we declare first, then use, and then discard.
A local variable is one that we create for a specific event only and then discard when the event has finished (the only exception to this is in the script resources, where a var declared variable is local to the script and then discarded). Why would we need them? Well, variables take up space in memory and it may be that we are only going to use them for one operation or function in which case we only need to have it in memory for that short time that it's used. This keeps your code base clean and tidy as well as keeping memory space optimised for the things that really need it. To declare a local variable we use the function var like this:

var i, num, str;
i = 0;
num = 24.5;
str = "Hi there!";

All of the variables created above will be "forgotten" (ie: removed from memory) at the end of the event (or script) in which they were created. You must be careful that the name you give var declared variables does not coincide with another instance variable within the object running the code, and also make sure that you have no intention of using the value stored in that variable outside of the event declare it in. These variables are used a lot in programs, especially in loops for counting iterations, or when using a value several times in one operation that is not going to be repeated again. Here are another couple of examples:

var i = 0;
repeat (10)
{
inventory = 0;
i+=1;
}

The above code creates a local variable called "i" and sets it to 0, all in the same line. Note that in previous versions of GameMaker you had to declare your local variables first and then assign them values, but in this version you can declare and assign them a value at the same time. The above code then uses this variable to initialize an array. As the variable "i" is not going to be used for any further functions in the instance other than this, it can be local in scope. Here is one more example:

var xx,yy;
xx = x - 32 +irandom(64);
yy = y - 32 +irandom(64);
instance_create(xx, yy, obj_blood);

Here we have used the local variables to store some random coordinates that we then use to create an instance. In this example you can see that it is not strictly necessary that we use these variables but for the sake of readability and ease of use, we do. It is MUCH clearer and obvious what we are doing there than if we used this code:

instance_create(x - 32 + irandom(64), y - 32 + irandom(64), obj_guts);

One other thing about var declared variables should be noted... As they are unique to the event that runs them, they can be used in any other instances through code too! This means that we can use these variables to set and change things in other instances using the "with()" construct (there is a section on this in the GML Overview section of the manual). The actual code itself would look something like this:

var num = instance_number(obj_Enemy);
with (obj_Enemy)
{
if num>10 instance_destroy();
}

The above code works because the var declared variable is local to the event (or script) it is contained in, not the instance, nor the game world, and so can be used in any function in any object as long as it is in the same code block.
Lesson 2.5 - D (Global Variables)
This section explains what global variables are and how to use them.
A basic description of a global variable is one that, once declared, belongs to no instance in particular and yet can be accessed by all. Just like local variables, global variables must be declared, but unlike a local variable, a global variable remains in memory until the end of the game. So, you can create a global variable to keep track of (for example) the number of bullets that the player has and then just update this variable at different points in the game. A global variable does not belong to any specific instance and can be accessed, changed and used by all instances at any time, but any change made to the variable are "global", in that all instances using the variable will be affected by the change. Let's have a look at an example:

global.food = 5;

We declare the "food" variable by first writing "global" and then a "." to tell GameMaker that this variable is now global scope. We will need to use this method from now on any time we are required to access or to change this variable in any way. So, we have created a new variable called "food" and we have declared it as global. Now, any instance can use and change this variable in any way and all other instances will "see" this. For example we could have a different food object that the player collides with and in the collision event we have:

global.food +=1;

We also have another object that draws this value like this:

draw_text(32, 32, "food = " + string(global.food));

With global variables we can change values and see those changes reflected in all instances of the objects that reference this variable. As with local variables you have to take care not to name your global variables the same as any instance variables as that will cause you problems and make bugs creep into your games due to variable overlap, which can be a difficult issue to debug sometimes. In general you should have a single script or object that declares all your global variables at the very start of the game (for example, in the Room Start Event), so that they are initialised and ready for any instance to use, and this also gives you a handy place to go back and reference should you need to check a variable name.

GameMaker: Studio has a collection of "built in" global variables too, so you should be aware of them as you may name one of your instance variables the same or wish to have your own global variable with the same name and wonder why you are getting errors! They are easy to spot, however, as they are shown in a different colour in the code editor and also come up in the auto-complete bar at the bottom. the majority of built in global variables are very specific and will only be used on rare occasions, but there are three in particular which are very useful.

score
health
lives
async_load

globalvar
The following method can also be used to declare global variables, but it is only included for backwards compatibility, and it is not recommended that you use this method for new projects as future versions of GameMaker: Studio may not support it.

The second method for creating global variables is to declare them as such using the globalvar declaration, much as you would a local variable using the var declaration. For example:

globalvar food;
food = 5;

Once declared in this way that variable is now considered global and requires no "global." prefix - which also means that it's a lot harder to identify global variables in your code and it's also much easier to get variable overlap as you use the same variable name in different objects - and the variable is accessed as follows:

food += 2;

or:

draw_text(32, 32, "food = " + string(food));
9 Comments
QMaster 8 Jul, 2024 @ 11:54am 
Is this still up to date?
GrungeBro 23 Jul, 2021 @ 7:06am 
kinda sucks that people do these kind of tutorials but never keep em up to date...just such a waste of time
Korone-Virus 28 Jul, 2020 @ 12:55pm 
This is obviously not still being 'up to date' as the last time it was updated was the same year it was posted.
I Haven't Had Sex Since 2003 25 May, 2020 @ 7:39pm 
Is this still up to date?
GameSmashDash 4 May, 2020 @ 12:10am 
To be honest coding in GM is not hard and it's a matter of what you're trying to make.
Recks 12 Apr, 2020 @ 5:17pm 
clickteam fusion is by no means as good or as powerful as GMS, its honestly pretty garbage
TeKidder  [author] 16 Apr, 2017 @ 10:24pm 
Thanks man. Because I know so much in GameMaker, Ill be creating a guide for Clickteam Fusion 2.5. I feel bad not finishing this one, but I cant deny CF2.5 is a GREAT tool. Ive been testing it compared to GMS and power wise I feel they are pretty close. (They both overpowered the other depending on what I was testing) But overall CF2.5 is faster development and far easier to use/understand so I feel its the better option of the two for me to persue/teach/develop in.
Wardiaper 16 Apr, 2017 @ 9:49pm 
Thanks for the guide. You put a lot of your time and knowledge into them. I've had Clickteam Fusion 2.5 sitting in my library. Maybe time to learn to use that too.

People like you taking the time to share your knowledge has made learning GMS (or any engine) infinitely better.
TeKidder  [author] 16 Apr, 2017 @ 8:55pm 
Sorry everyone. I have been using Clickteam Fusion 2.5 and have decided to stop using GameMaker 1/2. It is a great engine, just as powerful as GMS and the development process is twice as fast. I will not be coming back to GMS so I am done with these tutorials. Again I apologise but I will leave up this guide.