|
|
|
|
![]() ![]() |
Aug 26 2007, 03:57 PM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 223 Joined: 30-June 07 Member No.: 23,045 |
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: 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 ( CODE 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: CODE 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. 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" ( CODE { 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 ( 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 ( CODE 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 Astahost and if I've got some time free I'll help you out. Thanks! Mordent |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 6th September 2008 - 06:30 AM |