Hello, thanks for visiting GameML, if you are a Game Maker user, this is the site for you, please sign up, or login if you are already a member, or just browse the site! Welcome to GameML!

ATTENTION MEMBERS!!! USERS CAN NOW SIGN UP AGAIN!
Log in

I forgot my password

Search
 
 

Display results as :
 


Rechercher Advanced Search

Site Hits
Free hit counter
These stats started at 0 on July 7th 2009
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: http://gameml.iowoi.org/GameML-File-Sharing-h3.htmPlease add only games.
Create A GAMEML BLOG!
Make a Blog on GameML:http://gamemlblogs.wetpaint.com
Keywords


Game Maker Language Book

View previous topic View next topic Go down

Game Maker Language Book

Post by GmMkr on Thu Nov 12, 2009 6:19 pm

Quite honestly, I had no idea where to post this. I'm guessing this would be the place since it's a tool to teach. I'll put it in a quote. It's a book that I'm creating for those that wish to learn GML. It's going to cover every little detail in as much detail as possible. I know how frustrating programming books can be. I do my best to explain EVERYTHING!

Sadly, I will not be able to continue posting this here since I have somewhere else to worry about.

Here's all of the current chapters.

The rest will be posted at my forums. You do not need to sign up to read the new chapters posted almost every day.
(Almost...)

http://coderslounge.forumotion.com/forum.htm

Tell me what you think at that link as well if you decide to make a comment. :]
I won't be able to read your comments here.

It is suggested that you learn Game Maker's concepts first. Learn from a few tutorials and get really close with D&D.

Alright, so my first conflict was HOW to make this tutorial different from others... I want to make it easy to understand and I want to make SURE that you grasp the concept.

So this will be the order of each and every lesson.

1. Brief introduction as to WHAT we're going to be doing.
2. Basic buildup of the code.
3. Explain each section.
4. Use in an example.
5. Overview.

I think this will be the easiest way to go on about this.

I NEED YOUR HELP! Please, keep this topic alive. I don't want to be bumping this everyday and thinking that no one is interested. It would make me want to stop. I'm not asking you to force yourself to be interested, what I'm asking is that if you ARE interested then PLEASE POST!
_______________________________________________________

Most people begin with variables. That is not me. I will have a new way of doing things... Intro first.

Chapter 1
An introduction to GML
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Many of those that use Game Maker and use the D&D functions are quite satisfied with what they can accomplish. It's true, one can make an entire game with solely D&D and it may end up being amazing. However, D&D has many restrictions. For example, using D&D, one cannot check if a sprite is on a certain sub-image. What if when the sprite is on the third sub-image it should shoot something?

This is where GML comes in. GML gives more flexibility. There is more you can check and more you can do. With GML you can honestly accomplish just about anything you want to! It can be organized however you desire, it's much easier to edit, it can be moved easily, it's easily reused, it's very understandable, it runs faster, it's easier to find bugs, it can be commented easily, and much much more!

But, there is a downside. GML is a language and like any other language, you have to learn it. You have to memorize functions and what they do. You need to know WHAT you're checking for. What is it that you want? What do you want happening? How do you want it to happen?

After a while with GML, this is all very easy and becomes second nature to you, but when you're just getting started... not so fun. GML is tedious at times.

When learning GML do not get discouraged! It will be difficult and you'll wonder WHY your code isn't doing what it should! When others do it it ALWAYS comes out nicely, why doesn't it for you? That's a bad thought. Even the most professional programmers sit there for hours wondering WHY their code isn't working. So do not give up!

What I can promise you from these lessons:

-You will learn GML, enough to make an entire game with it.
-Your programming life will become easier.
-You'll be faster at coding.
-Your understanding of Game Maker will greatly increase.
-You'll be able to move on to other languages with more ease.
-You'll become a faster, more logical thinker.
-You'll be satisfied.

Just pay attention to these lessons and you WILL get there.

This was my first lesson, just to give you a quick intro as to what GML can do and why it's easier.

In the next lesson, we'll cover variables... Until then!

...................................................................................................

Chapter 2
Built-in variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In both this chapter and the next I will be thoroughly explaining variables. This chapter will only cover Game Makers built-in variables. I'll simply go in depth with the variables that you'll be using most.

First off, what is a Game Maker built-in variable?
A built-in variable in Game Maker is a variable that already has a value set to it which you can call at any moment. These values are not all constants so they do change. There's variables that check the width of the room or the starting position of an object. They are extremely useful and they do a lot of the work for you. Here's a few built-in variables and what they do.

xstart- This is the x coordinate that an object had when first created in the room. You would use this in cases where you want the object to return to its first x position by setting the objects current x position to xstart.

ystart- Same as xstart only this one is for the y coordinate.

room_width- This variable stores the width of the current room in pixels. It's useful for when you want to write a code for multiple rooms that have different sizes. Instead of writing lines of code and going to each room to find the width, you just use this variable.

room_height- Same as above, only this applies to the height of the room.

room_speed- This is the speed of the room in frames per second. This is useful for many reasons. One would be perfect timing. You can make something last five seconds by typing in room_speed*5.

sprite_index- This is the sprite assigned to the object that you use this variable in. It can be used to change this objects sprite by simply assigning it another sprite.

image_index- This is the same object's sprite, but it deals with that sprite's sub-images. It's great for animations or if you want something to happen during a specific sub-image. Maybe you just want the image to stop animating once it's reached a certain sub-image.

image_speed- The animation speed in which the image travels. Any number below one will slow the animation down. If you put a number higher the animation will not play at a faster frame-rate, it will instead skip sub-images. Useful for slowing down and speeding up animations.

speed- This is how fast the object will move in the game. It's pixels per frame. So if you put a speed a 2 and the room speed is 30: 2*30 = 60. In one second your object will move sixty pixels. That's not a lot. You can guess what this is useful for. You'll use it A LOT!

direction- The direction that the object faces. There are 360 degrees. 0 is right, 90 is up, 180 is left, 270 is down. It's a counter-clockwise circle. It's actually from degree 0 to degree 359, but since it counts 0 then there's 360 degrees. It's used for everything direction based and will once again be used A LOT!

image_alpha- This is the transparency value of an image. A value of 0 would make an image invisible and a value of 1 would make an image completely visible. You're not restricted to both values. You can be as specific as you want. You can set it to 0.5 for semi-transparency. You can even set it to 0.3542654 if you wanted to for some odd reason...

mouse_x- The x position of the mouse on the screen. This could be used to have objects follow the mouse by setting their x positions to mouse_x.

mouse_y- Same as above only it applies to the y position.


Alright, well I've covered some basic built-in variables of GM. There's a LOT MORE! Look in your help file. To me, these are the ones you'll use most. I went as in depth as I thought would be needed. In the next chapter I will cover custom variables. Till then! Razz

..................................................................................................

Chapter 3
Custom Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alright, this is the final chapter before we get into GML itself. In this chapter you will learn what a variable is, what it does, how it works, how to create it, and how useful variables are. And anything else I can throw in here to try to make you a pro with variables.

First let us learn a little about variables. What are they?
You can think of variables as empty boxes with names written on them. These boxes hold words or values, depending on what you want to store in them. Then, the value inside of these boxes can be changed. One can then use this box's value by calling the name written on it.

Basically a variable is something that you create to hold a value for you. It can be called later and it can keep track of things for you.

Here's a few examples as to what custom variables could be used for:

-Keeping a coordinate.
-Checking an enemy's health.
-Setting multiple scores.
-Checking speeds.
-Setting time spans between shots in a shooter game.
-Creating stats and unlockables.
-Drawing grids.
-Remembering the player's name.
-Etc.

Now, how does one make a variable?

It's honestly EXTREMELY easy. You'll usually name a variable something that you can associate with the task you want accomplished. Let's say that you wish to make a variable that will remember someone's name. You'd name it something like player_name. A variable cannot have spaces. It can only have normal text characters and numbers. If you're setting the variable to a value then you'd set it like so:

my_var = 1

If you're setting a variable to a string (which is just normal text with no real value) then you'd do it like so:

player_name = "Brandon"

Now, I know you're dying to know HOW to use these variables, but that's for another day. Right now, all you have to understand is what a variable is though. It just holds information. Be it a real value (a number of some sort) or a string (simple words with no real number value).

You can name a variable ANYTHING you want. However, to call that variable once again you must type its name perfectly! player_name and Player_name and PLAYER_NAME are three completely different variables! So be careful.

(This chapter is a bit long)

Now, when you create a variable it MUST be created in the CREATE event of the object first. This sets the variable. Also, this variable is local and only applies to the object it is set to. You cannot change it with another object unless that object changes it for the object it's set to. Don't worry about that making too much sense right now, it will in later chapters.

Last thing, global variables. A global variable is a variable that remains throughout the game from the moment it is created. It can be changed by any object and it does not disappear when going to another room. Usually you'd use a global variable to keep a score. (Or you can use the built-in variable called score ;]).

To make a variable global, all you have to do is add the word global and a period before the variable name. Like so:

global.player_name = "Brandon"

And that variable is now global. It can be changed by any object and called by any object.

I hope this all makes sense. Next chapter... syntax!
We'll finally be getting into GML! :]

Until then!

.............................................................................

Chapter 4
The GML Syntax

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Finally, it's time to get into GML itself! I believe that starting off by learning the syntax is the smartest way to go. So, this is the way we'll go. But first, what is the syntax?

Well, you know how in your primary language has rules? Place this in a certain order or add this comma here? Well, GML is a language and therefore it has a certain way of writing it, in other words, a syntax.

The only problem is that if you forget a quote on your English paper you'll be fine, if you forget a quote in GML (or any other language), you won't be forgiven so easily.

Syntax is EXTREMELY important to get down. After enough practice with GML you will stop making mistakes like setting variables incorrectly, however, you'll be facing syntax errors until the day you die. They're like taxes, you can't escape them.

You need to perfect your syntax so that Game Maker will know what it is that you're trying to tell it to do. Now, in this lesson we're going to use a very exaggerated and spaced out syntax. Why? Because it's easy to read and to fix. Although Game Maker does not require semi-colons at the end of your lines of code, it's good practice, so we'll be using them. A lot...

Now, here is an example of the GML syntax.

Code:

{
  if (keyboard_check(vk_left) && place_free(x-4,y))
    {
      speed = 4;
      direction = 180;
    }
}

See? It's nice and spaced out. Your actions have semi-colons. Now, let me explain everything you see there. Step by step. Seriously, I'm going to go down line by line.

Code:

{

This is the opening bracket. Game Maker doesn't require it but it's GOOD PRACTICE! So do it. Later on you can develop your own styles after you've gotten good at GML. (I still use these brackets, I like them.)
The opening bracket is just where the code begins.

Code:

  if (keyboard_check(vk_left) && place_free(x-4,y))

This line of code is asking the game questions. We're only focusing on syntax though. As you can see, it is indented. This isn't NEEDED but it's EXTREMELY useful. It makes it easy to debug your code because everything is easier to find. As you can see, after the if I added a ( and then I typed everything I'm checking followed by another ). Game Maker is very lenient and would let this slide sometimes. Don't ever stop putting it though. It's good practice.

Code:

    {

Once the if statement is checked I need to put another opening bracket. Why? Because everything between this opening bracket and the next closing bracket will be executed if the if statement is true. You do actually NEED this and no, Game Maker will not be lenient here.

Code:

      speed = 4;
      direction = 180;

Simple actions. Just notice how at the end of both of these lines of code there's a semi-colon. Yea, add those. They're part of the GML syntax as well as many other languages. The signify the end of that line of code. That specific action. Be careful, not adding them may be forgiven at times, adding too many of them will not be forgiven.

Code:

    }

This simply closes what the if statement will execute if proven true.

Code:

}

This closes the script you've just written.

As you can see, the GML syntax is pretty simple. You'll learn more about it as you read through this book. For this chapter I will be taking questions seeing as to how I can't explain it all in one chapter. You WILL learn more about the syntax as you read.

If you have any questions just post in this topic.

Until next time!

Next chapter: How Functions Work
We'll be getting into the language.

....................................................................................

Chapter 5
How Functions Work

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's been a while since the last chapter... I'm still considering making this into an actual book. I'm still debating with myself whether or not it'll be free. However, if you wouldn't buy it then I suggest you read up as much as you can! Anyways, let's begin.

In this chapter, I'm going to describe how a function works. What it does. What's it for? What can you achieve with functions?

Well, functions pretty much make the game work. You can't have a game without them. They create instances, destroy them, check everything, activate and deactivate instances, go onward to other levels, check for other levels, change instances, move instances, set properties, etc. Basically, everything.

Now, there's functions that simply perform an action, then there's functions that perform an action and return a value. There's also functions that one will us for simply checking everything. In later chapters, I'll even show you how to make your own functions! It makes life easier, but you need to know functions in the first place.

Also, most functions have arguments. What is an argument? Basically it's specifics given to said function. If you're going to use a function to create an instance then you'll need to add arguments that indicate the x and y positions of the created instance and what instance it is that will be created.

function(arg1,arg2,arg3)

Now, not every function has arguments as they simply give a command. You do, however, still need to add the ( and ). So it would look like so.

function()

Now, how would you write these in code? Let's use real examples.

The following function destroys the instance that holds it.

Code:

{
  instance_destroy();
}

Now, I'm sure you're familiar with the syntax as we previously covered that. As you can see, there are no arguments to this function. That's because it only has the task of destroying the instance. You still see that I used the ( and ). Now, there are many functions for checking things. These are much more popular as you will be using them to check everything in your game.

Let us say you wanted to check if a certain place is free of any solid objects. You would use this function to check.

Code:

{
  if (place_free(x,y))
    {
      //do something
    }
}

We used the place_free() function. It has two arguments. The x position and the y position. Also, now we have actions that will be executed. This is because we used an if statement (which you'll learn more about later) which checks whatever is between the ( and ). And between those parenthesis we have our function place_free(x,y) which checks if the position x and y is free. This function is used to return a value of true or false. If the value returned is true, then the following actions inside of the { and } are executed.

Now, I'm sure you have many questions about how if statements work and I'm sure you're curious about how else we can mess with these functions. Well in the next extremely long chapter, I will cover all of your curiosities in the simplest manner possible.

Next chapter: If, Else

...........................................................................................

Chapter 6
If, Else

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Forgive me for the extreme gap in time between chapters. I've been busy with college preparation and such. Lots to do. Anyways, let us continue.

Now, by now we know how to handle functions and variables, but do you honestly think you can make a game with just that? Absolutely not. Every game has HUNDREDS of different aspects to check. You want certain functions to run at certain times; or you want them to run for a certain amount of times; or you want them to run when something is true, or when something proves false; or etc. etc. etc.

Point is, you need to use what we call statements.

What are these statements?

Well, statements can check for certain specifications, or they can simply do something. An easy way of putting this is like so:

You have the function place_empty(x,y) but it will only return a value of true or false and you honestly cannot do much with that alone. You'll need to use a statement to be able to manipulate the returned result to your likings.

So, let's seriously break this down. Let's begin with the most commonly used statement of all.

The if statement.

The if statement is used to check whether something is true, or if it's false. Then it will execute whatever is between the { and }. I hope you remember our chapter on syntax because now is when you need to start using it.

We will not be actually testing any of these out, but for practice, I'd like you to open up Game Maker and do as you see written. It's for practice.

Now, the if statement works like so.

Code:

{
  if (<expression>)
    {
      <action>
    }
}

Let's go over this. The if statement has a ( and ) after it. This isn't NECESSARY when you're simply checking ONE expression. But what if you wish to check multiple? We'll get into that later. But still, one should ALWAYS use ( and ). It's organized and avoids error.

The if statement checks the expression within the ( and ). Then, if that expression is true (let's say it's a place_free(x,y)) it will execute whatever is within the { and }, however, if it checks back as false, it will not. Please, do not focus on the actual function place_free(x,y) as I promise I will show you how separate functions work in depth later on.

So it's a pretty simple statement right? Well, now let's say that if the if statement brings back a value of false you wish for something else to happen. That's where the else statement comes in.

Here's how it's used.

Code:

{
  if (<expression>)
    {
      <action>
    }
  else
    {
      <action>
    }
}

Now, I know you're intelligent and can guess how it works. But let's go over it anyways. Simply, the else statement just checks if the if statement brought back a value of false. If it did, then it skips the first set of { and } and it jumps to the { and } after the else statement. Basically, in English:

Code:

{
  if something is true
    {
      then allow these actions to occur
    }
  however, if it isn't true
    {
      then allow these actions to occur
    }
}

Pretty simple right? That's all you need to know about if statements and else statements.

I do plan to show you how other statements work, however I've decided to not include it in this chapter. I do not wish to overcomplicate things. I honestly want this to be a useful book. And almost every programming book I've read goes way too fast and confuses me. I promise, we'll cover every aspect of GML that you need to go to get you on your feet, walking, and maybe even running.

When you're done with this book, you WILL know GML. I hope you typed the above in your Game Maker programs. I know it wasn't needed, but it gives you simple syntax practice.

Next Chapter: Functions To Get You Started

Until then!

........................................................................

Chapter 7
Functions To Get You Started

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now, I'm sure I got you mad at me for taking so long to post chapters. So, to make up for it, I decided to post two. In this chapter, I'm going to cover some basic functions to get you started. I'll cover the most used ones. Once you get the hang of it, you can look into other ones yourself and they'll make sense to you.

Now, there's all sorts of functions for getting things done. Here's a list of the most important and useful ones.

instance_create(x,y,object); - This function creates an object at position x and y. It also returns the ID of that object. Basically, you can set this function to a variable and that variable will store the object's ID. When we make a game later on, you'll see this used. (At the end of the book...)

instance_destroy(); - This function has no arguments. It's quite self-explanatory. Whichever object you write this function in will get destroyed when the event it's set under happens.

move_snap(x,y); - This function will make an object snap to a grid of x by y. So if you entered 32 for x and 32 for y then your object would snap to a grid of 32 x 32.

instance_change(object,performevents); - This function transforms the current object that it's set in into the object written. In the performevents argument you must write either true (or 1) or false (or 0). If set to true, the event will perform its destroy event and the object it transforms into will perform its create event.

move_bounce_all(advanced); - This will make whichever object you set it to bounce off whatever object it collided with. The only argument (advanced) is just asking for a true or false value. If true, it will take slanted walls into account.

move_bounce_solid(advanced); - This will make whichever object you set it to bounce off of whatever object it collided with only if the object it collided with is solid.


That's enough to help you get started. Now let's cover some functions that check your surroundings and return values which you can play with later on.


place_meeting(x,y,object); - This will check if there is a collision with whichever object you indicate at position x and y.

place_free(x,y); - This will check if position x and y is free of any solid objects.

place_empty(x,y); - This will check if position x and y is free of any object at all.

place_snapped(x,y); - This will check if your object is snapped to a grid of x by y.

instance_exists(obj); - Checks to see if the object indicated exists in the current room.

instance_number(obj); - Checks how many instances of the object written exists in the room.

distance_to_object(obj); - Checks the distance to the object listed in pixels.


Well, every time we are presented with a new instance, I will be sure to describe what it does from this point on! For now, have fun with these!

CONGRATULATIONS! Right now, you can all be considered novice GML programmers. Wonderful! You're finally getting into the language and understanding how it works! I sure hope you all keep reading these chapters. This book WILL be finished, but I need your support!

Together we can make this happen!

Next Chapter: And, Or, And More.

See you all then!

.......................................................................

©️ 2009 GmMkr
(Yes, it's under copyright)
avatar
GmMkr
GameML Noob
GameML Noob

Posts : 24
Points : 28911
GameML Reputation : 2
Join date : 2009-10-26

View user profile

Back to top Go down

Re: Game Maker Language Book

Post by 3d on Thu Nov 12, 2009 6:39 pm

Great Job GmMkr!

_________________
Creator of GameML, Thanks for Visiting!
avatar
3d
Admin
Admin

Posts : 1227
Points : 42076
GameML Reputation : 66
Join date : 2009-05-31
Age : 35
Location : U.S.A

View user profile http://gameml.iowoi.org

Back to top Go down

Re: Game Maker Language Book

Post by GmMkr on Thu Nov 12, 2009 6:41 pm

Thanks. ^.^

So I'm guessing this is the right place then... Razz
avatar
GmMkr
GameML Noob
GameML Noob

Posts : 24
Points : 28911
GameML Reputation : 2
Join date : 2009-10-26

View user profile

Back to top Go down

Re: Game Maker Language Book

Post by 3d on Thu Nov 12, 2009 6:42 pm

It's fine. A good thing about GML is we allow as many posts as you want and we don't switch orders of subforums, and we dont really care where its posted as long as its in the general area thats correct. L:3

_________________
Creator of GameML, Thanks for Visiting!
avatar
3d
Admin
Admin

Posts : 1227
Points : 42076
GameML Reputation : 66
Join date : 2009-05-31
Age : 35
Location : U.S.A

View user profile http://gameml.iowoi.org

Back to top Go down

Re: Game Maker Language Book

Post by GmMkr on Thu Nov 12, 2009 6:45 pm

That's good. Forums shouldn't be too restrictive. Very Happy
avatar
GmMkr
GameML Noob
GameML Noob

Posts : 24
Points : 28911
GameML Reputation : 2
Join date : 2009-10-26

View user profile

Back to top Go down

Re: Game Maker Language Book

Post by The Dark Ninja on Fri Nov 13, 2009 6:35 pm

cool
avatar
The Dark Ninja
Super 500 GML
Super 500 GML

Posts : 1495
Points : 32854
GameML Reputation : 7
Join date : 2009-06-16
Location : Earth

View user profile http://www.thedakninja.tastyhamgames.com

Back to top Go down

Re: Game Maker Language Book

Post by -js1210- on Fri Nov 13, 2009 6:37 pm

That's cool. Make sure to do EVERY GM function
avatar
-js1210-
Super 500 GML
Super 500 GML

Posts : 1298
Points : 32442
GameML Reputation : 27
Join date : 2009-06-02
Age : 22
Location : United States

View user profile http://www.yoyogames.com/members/js1210

Back to top Go down

Re: Game Maker Language Book

Post by The Dark Ninja on Fri Nov 13, 2009 6:56 pm

not including some extensons
avatar
The Dark Ninja
Super 500 GML
Super 500 GML

Posts : 1495
Points : 32854
GameML Reputation : 7
Join date : 2009-06-16
Location : Earth

View user profile http://www.thedakninja.tastyhamgames.com

Back to top Go down

Re: Game Maker Language Book

Post by GmMkr on Sat Nov 14, 2009 7:00 pm

-js1210- wrote:That's cool. Make sure to do EVERY GM function

o.o
Thanks but... I think I'll include everything I find you need. Not EVERYTHING that exists. I don't have the time. XD
avatar
GmMkr
GameML Noob
GameML Noob

Posts : 24
Points : 28911
GameML Reputation : 2
Join date : 2009-10-26

View user profile

Back to top Go down

Re: Game Maker Language Book

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum