Gml Tutorial (BY Mailas Gonrai)
1-The basic conepts
What is gml? Gml stands for Game Maker Language. It gives you much more control and flexibilty than D&D does, and it is advised that you learn it, so you can make better games! Also, something in d&d could take alot of icons, while gml is just one line.
2- The coding interface
you have opened up the code editor... now what does it all mean?
Purple text: This is a funciton. All D&d icons represent gml functions.
Green text: This is a rescource name, like an object or a backgorund.
Blue text: THis is a built in variable, that oyu do not need to declare what so ever. Like x, y and room_speed.
Bold text: tHis is a statment, such as if, not and repeat. These manipulate the meaning of the code.
the box at the bottom: This is the gm t9! It predicts what funciton you are typing. Useul for spelling erros and checking if the function even exists in the first place.
Also, I need to tell you about paramters. Say you used the GM110.gif function. You must specify the x, y and the text. These are the paramters or arguments* of that function.
* Arguments are also soemthing that cna be changed externaly with scripts. But oyu odn't need to know that yet.
3- Basic conversion
Here is some gml code:
CODE
x=5
Wondering what this means? GM072.gif x and 5. Very simple and easy. Now, you know that little relative box at the bottom? Here is how it works in gml.
CODE
x+=5
x-=5
x=+5
x=-5
They are similar, but all very different.
It is divided into 3 or 4 parts. part one:The variable, in this case x part two: The relative function, this is not always there part 3: the = sign part 4: the value
CODE
[part one]: x [part 2]: + [part 3]:= [part 4]: 5
As you can probably see, without part 3, the code is floundering in water, in other words, it does not work. So part 3 is not changable, amking it a static piece of code.
Lets look at the code again, this time exlaining it as we go along.
CODE
// the double dash: // is the gml verison of :GM071:
x+=5 //this adds five to the current x vlaue
x-=5 // this takes five form the current x vlaue
x=+5 //this sets the current x value to vive. The + isgn is not needed
x=-5 // this sets the current x value to minus 5. In this case, the - sign is most certianly needed.
From what you have learnt so far, convert this to gml code: GM072.gif y , x divided# by 2. you obviously can cheta and look at the answer, but whats the point, you won't learn. Select this text to read it, it is the answer:
QUOTE
y=x/2
# for those who don't know, here are the mathmatical opertaions in real maths: +,-, * which is multiply, and / which is divide. No x and :- (imagine the dash to have smaller x value[moved over to the left])
4- The if statemnet
Say you want to move to the right, but only if your y value is greater than 200. this is where if comes in.
First of all:
number1<number2 number2 is bigger than number1
number1>number2 nuumber1 is bigger than number2
CODE
if y>200 //if y is greater than 200
{
x+=1 // add 1 to x
}
If y is bigger than 200, add 1 on to x. The {} are blocks. If y>200, anything inbtween the { and } is dopne. {=GM063.gif }=GM066.gif
Write the code for this: If x is bigger than 300, take 5 away from x
Answer (don't cheat!):
QUOTE
if x>300
{
x-=5
}
Aobut ordering, thse all do the same:
CODE
if y>1 { x=5}
if y>1
{ x=5}
if y>1 {
x=5}
if y>1
{
x=5
}
if y>1
{
x=5
}
Do whatever you prefer.
Now, we need to learn functions. Go to novice q&a and download Albahc BLackrats d&d to gml pdf fiel. Open it and find the gml for thesE: GM044.gif GM023.gif GM045.gif
Answer:
QUOTE
GM044.gif = showmessage(str)
GM023.gif = instance_create(x,y,object)
GM045.gif = show_info()
4- The and statement
The only use I know of this, is to add to the if statement:
CODE
if x>10 and y>10
{can_shoot=0}
Instead of asking if one thing is true (or not true when we look at the not statement in part 7), this can aks for multiplefactors of decision. can_shoot is only false is both x and y are greater than 10.
5- The else statement[/B]
GM064.gif What else can I 'say'?
[B]6- The or statement
What it says really.
CODE
if x>20 or y>20 {can_shoot-true} else can_shoot=false
As long as x or y is greater than 20, cna shoot is true, else it is false. Now you know the or statement.
7- The not statement
Right, time to explain agian, the last bit was easy.
CODE
if not name=Kenobi {show_message{"oh, i tohught you was him. So, who are you?"}
Tkae out not. if name = Kenobi, display thta message. Now put not in agian. It changes completely.
If name doesn't = Kenobi, show the message.
Task:
Convert to code: If global.ammo is not 0, draw text at x, y, the text is global.ammo#.
Answer:
QUOTE
if not global.ammo=0 {draw_text(x,y,global.ammo)}
# to write variables like that, put the variable name wiht no quotation marks, the "" things. FOr text and them, search variables and text in the novice q&a.
Tutorial finished. Congratulations, you now know basic gml! If you did not understand the tutorial, pm we with the reason why.
Fare well fellow programers, may your code be usefull and your games good.
EDIT: Really sorry you guys about some of the errors but I ripped it out of my tutorials on my game maker website and it has alot of pictures to help you with Game Maker so its kind of weird but it took me a while. Hope you like it!
What is gml? Gml stands for Game Maker Language. It gives you much more control and flexibilty than D&D does, and it is advised that you learn it, so you can make better games! Also, something in d&d could take alot of icons, while gml is just one line.
2- The coding interface
you have opened up the code editor... now what does it all mean?
Purple text: This is a funciton. All D&d icons represent gml functions.
Green text: This is a rescource name, like an object or a backgorund.
Blue text: THis is a built in variable, that oyu do not need to declare what so ever. Like x, y and room_speed.
Bold text: tHis is a statment, such as if, not and repeat. These manipulate the meaning of the code.
the box at the bottom: This is the gm t9! It predicts what funciton you are typing. Useul for spelling erros and checking if the function even exists in the first place.
Also, I need to tell you about paramters. Say you used the GM110.gif function. You must specify the x, y and the text. These are the paramters or arguments* of that function.
* Arguments are also soemthing that cna be changed externaly with scripts. But oyu odn't need to know that yet.
3- Basic conversion
Here is some gml code:
CODE
x=5
Wondering what this means? GM072.gif x and 5. Very simple and easy. Now, you know that little relative box at the bottom? Here is how it works in gml.
CODE
x+=5
x-=5
x=+5
x=-5
They are similar, but all very different.
It is divided into 3 or 4 parts. part one:The variable, in this case x part two: The relative function, this is not always there part 3: the = sign part 4: the value
CODE
[part one]: x [part 2]: + [part 3]:= [part 4]: 5
As you can probably see, without part 3, the code is floundering in water, in other words, it does not work. So part 3 is not changable, amking it a static piece of code.
Lets look at the code again, this time exlaining it as we go along.
CODE
// the double dash: // is the gml verison of :GM071:
x+=5 //this adds five to the current x vlaue
x-=5 // this takes five form the current x vlaue
x=+5 //this sets the current x value to vive. The + isgn is not needed
x=-5 // this sets the current x value to minus 5. In this case, the - sign is most certianly needed.
From what you have learnt so far, convert this to gml code: GM072.gif y , x divided# by 2. you obviously can cheta and look at the answer, but whats the point, you won't learn. Select this text to read it, it is the answer:
QUOTE
y=x/2
# for those who don't know, here are the mathmatical opertaions in real maths: +,-, * which is multiply, and / which is divide. No x and :- (imagine the dash to have smaller x value[moved over to the left])
4- The if statemnet
Say you want to move to the right, but only if your y value is greater than 200. this is where if comes in.
First of all:
number1<number2 number2 is bigger than number1
number1>number2 nuumber1 is bigger than number2
CODE
if y>200 //if y is greater than 200
{
x+=1 // add 1 to x
}
If y is bigger than 200, add 1 on to x. The {} are blocks. If y>200, anything inbtween the { and } is dopne. {=GM063.gif }=GM066.gif
Write the code for this: If x is bigger than 300, take 5 away from x
Answer (don't cheat!):
QUOTE
if x>300
{
x-=5
}
Aobut ordering, thse all do the same:
CODE
if y>1 { x=5}
if y>1
{ x=5}
if y>1 {
x=5}
if y>1
{
x=5
}
if y>1
{
x=5
}
Do whatever you prefer.
Now, we need to learn functions. Go to novice q&a and download Albahc BLackrats d&d to gml pdf fiel. Open it and find the gml for thesE: GM044.gif GM023.gif GM045.gif
Answer:
QUOTE
GM044.gif = showmessage(str)
GM023.gif = instance_create(x,y,object)
GM045.gif = show_info()
4- The and statement
The only use I know of this, is to add to the if statement:
CODE
if x>10 and y>10
{can_shoot=0}
Instead of asking if one thing is true (or not true when we look at the not statement in part 7), this can aks for multiplefactors of decision. can_shoot is only false is both x and y are greater than 10.
5- The else statement[/B]
GM064.gif What else can I 'say'?
[B]6- The or statement
What it says really.
CODE
if x>20 or y>20 {can_shoot-true} else can_shoot=false
As long as x or y is greater than 20, cna shoot is true, else it is false. Now you know the or statement.
7- The not statement
Right, time to explain agian, the last bit was easy.
CODE
if not name=Kenobi {show_message{"oh, i tohught you was him. So, who are you?"}
Tkae out not. if name = Kenobi, display thta message. Now put not in agian. It changes completely.
If name doesn't = Kenobi, show the message.
Task:
Convert to code: If global.ammo is not 0, draw text at x, y, the text is global.ammo#.
Answer:
QUOTE
if not global.ammo=0 {draw_text(x,y,global.ammo)}
# to write variables like that, put the variable name wiht no quotation marks, the "" things. FOr text and them, search variables and text in the novice q&a.
Tutorial finished. Congratulations, you now know basic gml! If you did not understand the tutorial, pm we with the reason why.
Fare well fellow programers, may your code be usefull and your games good.
EDIT: Really sorry you guys about some of the errors but I ripped it out of my tutorials on my game maker website and it has alot of pictures to help you with Game Maker so its kind of weird but it took me a while. Hope you like it!
