Game Maker: tips for beginners and intermediate-ish users
Game Maker is a software that makes making games easy!
Game Maker accommodates the creation of cross-platform and multi-genre video games using drag and drop action sequences or a sandboxed scripting language known as Game Maker Language, which can be used to develop more advanced games that could not be created just by using the drag and drop features. GameMaker was designed to allow novice computer programmers to be able to make computer games without much programming knowledge by use of these actions. Even better you can find it on Humble Bundles or sales super cheap at times! Today I'd like to share some tips with you!
- Starting with Drag n Drop is fine, but learn GML as quickly as possible! Not only is it easier to organize your work into scripts - but it's way way waaaay more powerful! Imagine trying to build a house with an old fashioned screwdriver instead of with a power drill! You can do it, and maybe just as well, but it's going to be a lot harder.
- It's never a case of 'the code just doesn't work'! I don't know how many times I've tried to code something, and it wasn't working, and for the life of me I couldn't figure out why. I think every programmer's natural thought is 'It's just not working and there's no reason why...' Sorry, bucko - you made an error! Go and hunt that sucker down!
- Speaking of errors: TRY TO SOLVE YOUR OWN! Posting here or googling around for help is fine, but it's better to dig into your own code and learn that lesson the hard way. You'll learn new best-practices and you'll prevent yourself from making the same mistake again in the future.
Do NOT copy paste code into your game from websites and tutorials! Type it out line by line, consider what each line does and look at how the author made it all work together! You'll learn so much more quickly! Even if you make spelling errors and have to go back and fix them, it's going to be good for you.
NAME YOUR VARIABLES LOGICALLY! I hate digging through other people's code and seeing variables called things like xx, xy, yy, xy1, xy2, gravity1, gravity 2, etc. Name them exactly for what they do. If someone else is reading your code for whatever reason, your variable names are great hints to them for what you're trying to do.
Now, on to some more specific and advanced things:
- Build everything to work by itself and to be self contained. Example: My game is a 2D shooter. The 'shoot' command input and all code for shooting is held in the individual gun objects, NOT the player object. Why is this important? Because now, if the gun isn't in the game for some reason, there's no issues with errors and trying to reference code that doesn't exist. If the player isn't holding a gun and pushes the shoot button, nothing happens. Even better: I can give those guns to enemy characters now, and with barely any coding, make them fully functional in enemy hands as well.
- Put as much into scripts as you possibly can. My player's step event looks similar to this:
STEP:
if room==gameRoom
{
scr_getInput(self)
scr_getCollisions(self)
scr_checkStats(self)
scr_doGravity(self)
//start finite state machine
By dividing your code into scripts more than just dumping it into step events, you can keep things self contained and independent from each other (a recurring theme!) and errors become very easy to isolate and chase down.
- Reset your variables when you're done with them! I recently made auto turrets for my game that target and fire at enemies. They kept stopping their attacks as soon as they killed 1 or 2 guys, and that's because they weren't resetting to 'not having a target' and weren't actively looking for new ones. Sounds simple, but it took me over an hour to debug. It was a line as simple as
STEP:
if target[z].dead==true
target[z]=noone;
This way, as soon as the turrets target was killed, it would actively hunt for another one, because the code to acquire targets only ran if target[z]==noone. Derp!
(The turrets now! )
- Organize your code! Use that TAB button! PROTIP: Formatting it on Steemit is rough if you're posting code. Instead, you can pre-format it in GM:S! Highlight all of your code, and press TAB. That'll put 5 spaces in front of each line. Copy it like that, WITH the spaces, and paste it here for ezpz code formatting!
For instance:
if(stuff)==true
{
//do stuff
//do stuff
if(otherStuff==true)
{
//do stuff
//do stuff
//do stuff
//do stuff
}
else
//otherStuff
}
is so much nicer to read than:
if(stuff)==true
{
//do stuff
//do stuff
if(otherStuff==true)
{
//do stuff
//do stuff
//do stuff
//do stuff
}
else
//otherStuff
}
Make it a habit! You'll be happy you did!
- LASTLY FOR NOW: BACK UP YOUR WORK DAILY / HOURLY / WHATEVER!!!! Last night I was working, and I hadn't backed up in a week or so. I duplicated an object in my game to make a new version of it trying to improve it, and dumb me forgot to actually DUPLICATE it first, so I was editing my main object and I tore all of the code apart (few hundred lines). Realizing what I did, I tried closing GM:S without saving, but the jerk autosaved itself anyhow and I was at ground 0, rewriting a few hundred lines of code. Not a big loss, but could have been worse!
I hope at least someone finds some value in this long rambling post, if you guys like it I'll try to post more things like this in the way of tutorials and such. Let me know!