10 Things That Coding GMod Taught Me

1. Inheritance. Before I started playing with the Source Engine I had no idea of how to use inheritance. In fact, when coding all of my NPCs in Facewound the code was copied and pasted directly from another NPCs to build upon.

2. Interfaces. Interfaces kind of changed the way I approach nearly everything in my coding. Putting specific things into a separate DLL forces you to make your code more modular. It also encourages reusable code, speeds up compiles and I guess it reduces bugs (or at least makes it more obvious where they are).

3. I don’t like Lua so much. I know it’s a weird thing to say, considering how much GMod uses Lua.. but if I could do it again I’d really try to use something different if it existed. Lua has a lot of good stuff, but some things are annoying. Like the syntax. It seems like they do stuff to be different. They say it’s to make it more newbie friendly, but how is

--[[
This is a comment
--]]

more newbie friendly than

/*
This is a comment
*/

It isn’t, it’s just being different for the sake of it. Plus none of the fundamentals like |, <<, +=, -=, *=, /=, &= or |=. Not newbie friendly I'm afraid. I don't see why adding them would mean that newbies would have to use them. I guess I just want it to be PHP. I wonder if you could use PHP as a game scripting language..

4. Separate drawing and thinking. In Facewound all the objects would think as they were being drawn. So if you had 60fps, the AI was thinking 60 frames a second. The movement code was like


x = x + xvel * frametime
y = y + yvel * frametime

In retrospect, they should have been separated. The AI should have thought like 10 times a second, and draw should have lerped between the new and old positions automatically.

5. Vectors. I thought I understood Vectors until I used Source, but Source makes it all so simple compared to something like the DirectX SDK. Things like discovering Forward, Right and Up vectors were like huge epiphanies.

6. Matrices. Matrices are easy. I’ve never been that great at maths (got C in school (10 years ago)). But luckily enough you don’t really have to be to use them. It’s just basic shit like rotate this much, move this much, scale this much. It always seems crazy how all the game dev books/websites I read made them seem so complicated, actually telling you about the numbers inside. You don’t really need to know that. It’s like telling someone about assembly when all they want to do is add two numbers. I mean look at this shit.

7. Source Control. I never used Source control until about GMod version 5. It’s invaluable in bug tracking. For example, you find a bug that shows up in version 6 but not 7. You just diff the changes in the code. Or maybe you start pursuing something that turns out to be a big load of shit, you just revert your code to what it was. Plus it’s another backup of your code if things go tits up. ANd if you’re making something open source, you can host it at google – you don’t even need to set up a SVN server.

8. Visual Assist Rocks. It’s so hard to go back to coding without it once you have it for a couple of weeks.

9. Do it properly. Adding hacky shortcutty crap to your code might not seem like much at first, but it’s 100x harder to fix it and do it right when so much other code depends on that hack. Take the time to do it right the first time will save a lot of time in the long run.

10. Don’t trust modders. If you’re giving people the opportunity to mod your game, they’re going to be doing dumb stuff.

For example, in GMod getting a lot of text from the server to the client can be a bit of a chore because you can only send just under 255 characters at a time. So some modder, in his infinite wisdom, sends console commands to the client which clears the console, writes out a bunch of text, then condumps. He can then open up the condump file and the text is there. Yeah that works, but it’s a huge fucking hack and ends up generating 100′s of condump334.txt files in your garrysmod folder.

“A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools.”