Jump to content
xisto Community
Sign in to follow this  
Mordent

Game Maker: Drag-and-drop To Gml

Recommended Posts

Game Maker: drag-and-drop to GML

 

By: Mordent

Created: 26/08/07

 

Game Maker is a relatively simple piece of game development software, which you can find here. To start off with, you'll be using "drag-and-drop" actions to make your games, but after you've made a few you might be wondering how to convert those actions in to code. The language Game Maker uses is, imaginatively, Game Maker Language (or GML). That's what this tutorial is about, and after it you'll be able to develop more complicated games and get the most out of Game Maker. I should stress that I'll be assuming you've made a few games already, and know what some of the drag-and-drop actions do. If you haven't made a game with Game Maker yet, go download it now and go through the tutorials that come with it to learn a bit about the interface.

 

Why use GML instead of drag-and-drop actions?

 

Anything you can do with drag-and-drop you can do with GML, but there's some things you can do in GML that you can't do with the drag-and-drop actions. Add to that the fact that Game Maker is normally used as a platform to other, more commercially recognised programming languages and you'll need to understand the ideas behind using GML.

 

How do I use GML?

 

GML is the programming language you can use instead of the drag-and-drop actions. To use it, you need to add an "Execute Code" action to the appropriate event (it can be found under the "Control" tab). If you need a hand finding it, it looks like this: Posted Image

 

This action can take the place of all other drag-and-drop actions, as well as do a lot more. Once you've added it to the event, you get a window pop up that allows you to enter code (in GML). One important aspect of GML is that it's suprisingly easy to write something in two similar (but still different) ways and get the same result. It also becomes important to think about what the actions you've previously used really do.

 

Using GML

 

As an example, what does the "Jump to Position" action (Posted Image) really do? When you open it you get to set the x and y co-ordinate of the instance in the room. All it does is set the variables x and y to the numbers you put in the box. Each instance has a selection of variables built in to it that Game Maker uses to do certain things. Setting x to a co-ordinate means your instance moves to that position. Want to do this in GML? The code for setting variables is pretty easy:

 

variable = value;
So, if you want to move your instance so it's 128 pixels from the left hand side of the room, you can use:

 

x = 128;
On a side-note, the semi-colon isn't strictly necessary (as in Game Maker will work without it), but for both more complicated programs and languages it's vital. It simply means that the statement you just typed in has ended. Get in to the habit now and it'll save a lot of hassle later on. :D

 

Just as you can put drag-and-drop actions one after another normally, you can write several lines of code rather than having a seperate "Execute Code" action for each. The more code you put in, however, the more important keeping your layout tidy becomes. As an example, indentation is very important. Tinkering with Game Maker's preferences (you have to have Advanced Mode on to do this) lets you play around with how Game Maker indents and so on for you (Preferences - Scripts and Code). Personally I have both Smart Tabs and Automatic Indentation off, simply because I like to do everything myself. One point to note is that pressing Tab while in a code window is the equivalent of pressing Space four times.

 

Curly brackets ("{" and "}") are another important aspect of layout, but these are far from optional. They're the equivalent of the "Start Block" (Posted Image) and "End Block" (Posted Image) actions, and are used just as they are. I tend to put them around all code (as in the example below) and indent my first line, but again that's purely personal preference. Anyway, the code below shows how you can have more than one line of code within the same Execute Code action.

 

{	x = 128;	y = 32;}
That particular chunk is the GML equivalent of the "Jump to Position" drag-and-drop action, and it moves the instance that runs it to co-ordinates 128,32. Quite a few of the drag-and-drop "actions" are really just setting built-in variables within the instance to a certain value. The "Speed Horizontal" action (Posted Image) just sets the hspeed variable. "Move Free" (Posted Image) sets both the built-in variables speed and direction to the values you specify, which tells Game Maker to move the instance in a certain direction at a rate of however many pixels per step. Quite a few variables actually do something in Game Maker, so you have to watch out for them when you come up with variables of your own to avoid conflict.

 

So how do you convert drag-and-drop actions in to code? A large number of D&D (drag-and-drop) actions have a direct code counterpart. As an example, the "Create Instance" action (Posted Image), which does what it says on the tin, can be substituted with:

 

instance_create(x,y,obj);
The bit before the brackets is the function it needs to do, with the parts inside (seperated by commas) being the parameters (known as "arguments"). Replace the x, y and obj with whatever you'd normally put in the D&D action's boxes.

 

The first thing I suggest you do after understanding a bit about how GML works is to convert one of your simple games from D&D to code. Go through each action in turn and work out what it's really doing. The Game Maker documentation comes with a list of all of the functions available, and although some D&D actions may take a few lines of code ("Jump to Position" being the example above) doing this gives you some familiarity with the common functions as well as to make sure you know what you're doing. While you're doing that, I strongly suggest you read the GML Overview in the help file as well. It doesn't tell you how to make your games (as in the order you need to put your statements and so on), but it gives you an explanation of how to use some of the more useful (and complex) statements, such as for-loops; if statements; switch statements and so on.

 

Anyway, I hope this has given you a shove away from D&D and helped you learn the basics of getting started with GML. Once you know how to use it you can write games far quicker and to a more complex level than you otherwise could. If you need a hand with it, PM me on Xisto and if I've got some time free I'll help you out. :blink:

 

Thanks!

 

Mordent

Share this post


Link to post
Share on other sites
Need help to find a gamerGame Maker: Drag-and-drop To Gml

Replying to MordentSorry Bud, what am I’m trying to do is make something that will sound like a v8 car and play it through my Car speakers. Something like Sound racer or http://forums.xisto.com/no_longer_exists/ I am thinking is if I can have someone make me a Game that I can use with a Racing wheel, I can then hook it up to the cars Accelerator and Make it sound real with shift points.It might sound Difficult but not.http://forums.xisto.com/no_longer_exists/ this but with my own sound and be able to use a racing wheel to control it.Thanks for your time hope you can help

-reply by Jesse

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.