The Line Game


I decided to take some of what I’d learned in the Tom Francis tutorials and use it to make a small game of my own. The goal wasn’t so much to create something that I’d actually want to play as to get some good practice with the techniques involved.  I wanted to make something very different from the tutorials. The game I ended up with was a version of Lines (That smartphone game where you match 5 blocks and they disappear). More on what I learned after the cut. I wanted to create a game that wouldn’t be too huge a project, but would make me learn some new techniques and get some experience using the skills I’d already learned. Lines seemed a pretty good first game to do. In case you’re not familiar with this particular match game, the rules are fairly simple:

  1. Each turn 3 blocks of random colors are added to random squares on the board.
  2. After the blocks are added, the player can click on a block, then click again to move it to any empty square as long as there’s an unblocked path from the old spot to the new spot.
  3. If there are 5 blocks in a row of the same color, they disappear.

I probably won’t release the code since it’s buggy and poorly commented, but if anyone wants to know how I did something please ask and I’ll post code examples.

Lessons Learned:

GML’s Scope is strange. If you’re not familiar with other programming languages, a variable’s scope is where it can be seen. For example, if a variable has object scope, it means you can call that variable from anywhere in the object. I discovered the hard way that Game Maker’s language (GML), has some odd scope rules. It’s easy, for example, to create by accident a variable in a script that can be read from outside of the script. This is terrible and bad and everything that’s wrong with the world today, because the whole goal of a script is to create a closed piece of code that you can use without worrying about how it works. So the moral is to be careful about what kind of variables you’re creating.

Game Maker’s functionality is great out of the box. It gives you a lot of powerful functions right out of the gate. For example, I needed to be able to get a path from one square to another. Pathing AI is a royal pain, but I was able to just use GML’s mp_grid_path functions to get a path from A to B.

Beware of Memory Leaks. You don’t have to worry about this with some of the simpler functions, but be aware that some of the more complicated functions like the path and grid creation functions allocate memory that has to be put back by destroying the objects. Otherwise, your program will keep using more and more memory while you test it, and will eventually crash. What’s worse, it might also make the editor crash. As for as programming environments go, GameMaker seems to be more crash prone than Visual Studio. Of course in all fairness Visual Studio was made by Microsoft, which has money to burn.

Things don’t always happen when you think. At one point I kept banging my head against a wall on a piece of code where I used instance_destroy(), but the code acted like the object was still there. After digging in the help docs, I found out that instance_destroy doesn’t actually destroy the object until the end of the Step event. Which leads to….

Game Maker’s help docs are great. Just click the middle mouse button on a function, and you get some real quality documentation. I use Microsoft’s Visual Studio a lot for my work, and I have to say I like Game Maker’s help system better than rummaging through Visual Studio’s MSDN pages on Google.

Impose your own order. Some programming languages are written in such a way that you almost have to write your code in an orderly manner. GML is not one of those languages. It’s easy to write badly organized code. The moral here is that you want to plan out the structure of your program and keep things organized, or you’ll have problems as time goes on and your code base gets larger.

All in all I think the project went pretty well. It’s a different experience writing your own game than following and modifying a tutorial. The result wasn’t a game that you’d actually want to play, but it was helpful as practice and as a test bed for some functions I wasn’t that familiar with.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s