Game Maker basic commands
Once you’ve understood :
- GM is event based,
- How to launch the first event,
- Associating actions to events
You can launch your scripts (select an object and the control tab to the right, scripts are in the code section under questions and others) and not end up asking yourself why there’s just a blank screen. You’re ready to try some basic coding.
The point of this tutorial is to teach you how the most basic work. Later tutorials will apply basics to concrete examples.
If :
This command’s basic articulation is as follows :
If something is true
Do this
An if command can litterally contain pages of code. Something is true can actually be a combination of many things.
When two or more things need to all be true for the condition to be true. In this case they are associated by &&, which means and. Sometimes if just one of the listed conditions is true then they are associated by ||, which means or.
There can even be a combination of both.
Do this is typically even longer.
So as to contain the condition that is checked and what needs to be done if it is true, the if command can be written as follows :
If ((something is true && somethat is true) || someotherthing is true)
{
Do this ;
Do that ;
Do this as well while you’re at it ;
}
each command line finishes with a semi-colon ( ;).
Sometimes you’ll want the program to do things if the condition is true, and other things if it is false. That’s where else comes in.
If ((something is true && somethat is true) || someotherthing is true)
{
Do this ;
Do that ;
Do this as well while you’re at it ;
} else
{
do this other thing ;
do that other thing ;
}
Here is an example from the Swords & Sorcery code (this runs the search function and determines if something is found when the player searches the area Peregrine is in):
if (global.options_disabled=0)
{
// essential loots
if (global.posx=16 && global.posy=17 && global.questlog[170] = 1 && global.currentmap=17)
{
checkitems();
if global.itemcheck=0 global.loot_for_quest = 1050;
}
if (global.posx=11 && global.posy=13 && global.questlog[70] = 1 && global.currentmap=7)
{
checkitems();
if global.itemcheck=0 global.loot_for_quest = 1100;
}
if (global.posx=12 && global.posy=13 && global.questlog[80] = 7 && global.currentmap=22)
{
checkitems();
if global.itemcheck=0 global.loot_for_quest = 1010;
}
if (global.posx=17 && global.posy=12 && global.questlog[300] = 2 && global.currentmap=30)
{
checkitems();
if global.itemcheck=0 global.loot_for_quest = 1040;
}
// **********************************
if (global.newgold > 0 || global.loot1>0 || global.loot2>0 || global.loot_for_quest <> 0)
{
screen_redraw();
if (global.newgold > 0)
// manage gold found
{
draw_text (350,585 + findspot*35, global.newgold);
draw_text (450,585,’GOLD!’);
screen_refresh ();
sleep (1000);
findspot+=1;
}
global.gold = global.gold + global.newgold;
global.newgold = 0;
// ****
if (global.loot1=0 && global.loot2=0 && global.loot_for_quest = 0)
{
global.lootfoundroll = random (1000);
if (global.lootfoundroll <= global.lootprob1)
{
global.lootpos1 = random (1000);
if (global.loot1=0 && global.loot2=0 && global.loot_for_quest = 0) for (i=1; i<=40; i+=1)
{
if (global.lootpos1 >= global.itemlootfloor [i] && global.lootpos1 < global.itemlootfloor [i+1])
global.loot1 = i;
}
if global.loot1 = 0 global.loot1 = 1;
}
}
if (global.loot_for_quest <> 0) global.loot1= global.loot_for_quest;
if (global.characterpackedspot6[1] <> 0 && global.loot1<>0)
{
draw_text (350,585 + findspot*35, ‘No space left for:’);
draw_text (650,585 + findspot*35, global.itemname [global.loot1]);
screen_refresh();
sleep(500);
findspot+=1;
} else if (global.loot1>0)
{
draw_text (350,585 + findspot*35, global.itemname [global.loot1]);
screen_refresh();
sleep(500);
findspot +=1;
global.newitem=global.loot1;
add_to_inv();
global.loot1=0;
global.loot_for_quest = 0;
}
if (global.loot1=0 && global.loot2=0 && global.canloot=1)
{
global.lootfoundroll2 = random (1000);
if (global.lootfoundroll2 <= global.lootprob2)
{
global.lootpos2 = random (1000);
if (global.loot1=0 && global.loot2=0) for (i=1; i<=40; i+=1)
{
if (global.lootpos2 >= global.itemlootfloor [i] && global.lootpos2 < global.itemlootfloor [i+1])
global.loot2 = i;
}
if global.loot2 = 0 global.loot2 = 1;
}
}
if (global.characterpackedspot6[1] <> 0 && global.loot2<>0)
{
draw_text (350,585 + findspot*35, ‘No space left for:’);
draw_text (650,585 + findspot*35, global.itemname [global.loot2]);
screen_refresh();
sleep(500);
findspot+=1;
} else if global.loot2<>0
{
draw_text (350,585 + findspot*35, global.itemname [global.loot2]);
screen_refresh();
sleep(500);
findspot+=1;
global.newitem=global.loot2;
add_to_inv();
global.loot2=0;
}
} else if (global.newgold = 0 && global.loot1=0 && global.loot2=0)
{
draw_text (350,585,’Nothing!’);
screen_refresh();
sleep(1500);
}
global.lootfoundroll=0;
global.lootfoundroll2=0;
findspot=0;
}
The entire script will only be done if global.options_disabled=0. Nothing happens if that’s not true. I added that because I didn’t want people to search while a game character was talking to them, in which case I assign global.options_disabled=1 when it starts and put it back to 0 when it ends.
You see that whether something is true is often determined by a simple math function like global.variable > 0. Then Do this is a list of commands like drawing text, assigning values to other variables…
Now you should fully understand if an dits full potential.
You also understand the limits of GM’s drag and drop. Scripts like this are actually much more easily built by writing them out.
You’re ready to go on to another command, or try to build your first GM game further.
Have fun !
P.S. Don’t be discouraged if you can’t make everything out in the example. There is good reason for this. It’s complicated and it took me quite a while to debug it. Also, it is linked to other scripts.
The game has 163 scripts ! Some are simple and lots aren’t J

