Programming!
Lets get an overview.
If you want to go right in to programming with gamemaker then go a head past the paragraph below and learn some GML!
All programming languages use these operators:
If you want to go right in to programming with gamemaker then go a head past the paragraph below and learn some GML!
All programming languages use these operators:
IF, THEN, ELSE, WHILE, WHEN, FOR, DO.
There are some more but these are the most important that are used in all programming languages. You just can't get around them. These operators are kind of self explanatory. IF this happens THEN DO this ELSE WHILE this happens DO this and WHEN this happens DO this ELSE this. Now the DO actually means do this no matter what. The FOR operator actually creates a loop and kind of files through variables and numbers. They normally are used to flip through indexes of ARRAYS. ARRAYS are used again, in every programmings language. What they really are is just a list. A variable contains 1 value right? (yes it does) Well an ARRAY holds lots of values all under one name so you can say that the ARRAY is called "list", so there is list[1] list[2] list[3] list [4] and so on for the rest of Rn(all real numbers). Now because every thing is Zero based in programming it actually goes: list[0] list[1] list[2]. Get it? So even though there are 3 elements to the list, if you say list[2] it's actually grabbing from the 3rd element. See:
element number 0 1 2
element amount 1 2 3
So even though you have 3 elements. The 3rd one is element 2. You might still be confused but that's ok! Because this topic will be fully covered later right now we have some fun to get to!
Now lets get to the point. In order to do something, you know make a program or game, you must learn a programming language. You already now know the basics of most programming languages but you need to run a script in order to make something happen. Gamemaker uses GML. So this page will cover that, if you want to learn a different language then please click one of the buttons below!
element number 0 1 2
element amount 1 2 3
So even though you have 3 elements. The 3rd one is element 2. You might still be confused but that's ok! Because this topic will be fully covered later right now we have some fun to get to!
Now lets get to the point. In order to do something, you know make a program or game, you must learn a programming language. You already now know the basics of most programming languages but you need to run a script in order to make something happen. Gamemaker uses GML. So this page will cover that, if you want to learn a different language then please click one of the buttons below!
GML
Welcome and comgrats! GML is an awesome programming language! Part of what makes GML unique is that it has built in variables, and some of those variable are : speed, direction, x, and y.
These 4 vars are what will allow you to make a basic game in flat out code. For example you can say: { speed = 4 direction = 90} This will move the object of which this code is placed in to move up! 90 = up 0 = right 270 = down 180 = left. Get it? You can set speed to -1 and that will make the object go the opposite direction from the direction set in the code very slowly. X and Y are the vars that keep track of the objects location. The X location and the Y location. What you can do is set it to a relative number. Like: x += 4 This will make the object jump 4 pixels to the right. Why? Because X goes sideways so a positive number goes to the right and a negative number goes to the left. If you want to practice writing GML you can try the practice code section below. Code practice:Just typing the code down somewhere really helps you remember it. So take advantage of that. You can just type right here, copy the code, and try it out with Gamemaker on your own computer! You can just look at the code examples to the side, and type them in here. To make a variable simply type:
var variablename; Variables are used in almost every script of code that you will ever write. Why because variables store information!
You can type: var hello; And now hello is storing the number to 2, or in other words hello now has the value of 2. Variables are not very limited. You can store text as well! Normally when writing code it's called a string.
var hello; Now the variable hello is storing the string "Hello World!"
You can use this variable to say this to the user like this: var hello; When you run this code, a box will pop up and say: Hello world! Why? Because you are using a function called show message, this function shows a message to the user in a pop up box, and when you told it to display the information held by the variable hello it did and the information of hello is the words "Hello world!". You do not have to use variables. You can just say:
show_message('Hello World!') You might have noticed that this time inside the () I placed '' that is because that means that what ever I place inside those is a string. Before I wanted to use a variable that held a string, not a direct string.
Going back to variables you can add them multiply them and divide them. var hello, hi, greetings; If you run this code then you will see the number 23.
That is because the script was run from top to bottom (as always) and it first established that there were 3 variables hello hi and greetings, then it realized that hello = 3+4 it added it up and knew that hello = 7, then it saw that hi = 5*6, a definite 30, then it saw that greetings = hi - hello, knowing that hi = 30 and hello = 7 it arrived at the conclusion of a total 23. Then it was told to tell the user in a pop up box what it had just found out: what does greetings =? 23! So you see, it's very simple. You just got the computer all exited and let him tell you what he found out. No. Actually you just made a program that calculates variables and displays the answer to the user. Do you feel smart? You should! Because you know now how to program! Want to know more? Well this page is still in progress: For a really good gml reference got to: http://www.gmdeveloper.com/gml/basic_programming |
{
if (expression) then } ...................................... { repeat(100) // repeat 100 times (statement); } ...................................... { show_message('Hello World') } ...................................... { you = get_string('who are you?','nobody' ); show_message('hello ' + you + '. Welcome to the game.'); } ...................................... { if (expression)&&(expression) then (statement); } ...................................... { if (expression); { (statement); (statement); } } ...................................... < less then > more then + - add & sub == equal to ! NOT != NOT equal to MOVEMENT ....................................... { if keyboard_check(vk_left) then hspeed = -4 if keyboard_check(vk_left) then hspeed = 4 if keyboard_check(vk_up) then hspeed = -4 if keyboard_check(vk_down) then hspeed = 4 } ....................................... NOTE: == is different from =. you would use = in a comparison. like: If speed = 6 == is used to set something to the value of something else |