So you want to be a video game programmer? – part 5 – The Method

…CONTINUED from PART 4. Or start at Part 1.

This post is presents an algorithm of sorts for learning to program. It applies not only to the fundamentals, but to all aspects, including the acquisition of small component skills. Thirty years after learning, I still follow the same basic procedure. To tell the truth, modified, it works for leaning most things.

Step 1: Goal. Invent some manageable goal that excites you (in a later context as a profession “excites” is often replaced/supplemented by “need”). My first program was a text-based dungeon master (see here). If you want to be a video game programmer, there’s nothing better than a game. If it’s one of your first programs, make it damn simple. Copy some REALLY REALLY old and simple game like anything from before 1981 (PongBreakout, etc.). Truth be told, using text only for a couple weeks/months might not be a bad idea. Graphics just complicate matters. They’re awesome — and you’ll need them soon enough — but first the fundamentals, like variables, flow of control, scope, etc. Any individual task should take no more than a few days. If your goal is bigger than that, subdivide.

Step 2: Environment. All programming is done in the context of some environment, and you must learn about it. You need to start with a simple one. In my case it was mostly AppleSoft BASIC. For learning interpreted is good. Some decent starter environments today are Python, Ruby, Flash, Lua. DO NOT START WITH A LANGUAGE LIKE C. I will elaborate on this environment question in a separate full post, as it’s a large topic and highly religious for programmers.

Step 3: Research. This means reading. If you don’t like to read, either learn to or find yourself a new career. I’m serious. Reading separates the Neo Cortexs from the gibbering marsupials. I’m serious. Be a New Cortex. Your love of reading must be so extreme that you can stomach slogging through 900 page Library Reference Manuals (maybe not at first). Programming is full of details.

Step 4: Theory. Get out a pad of paper, a text file, Evernote, or whatever. Design what you are going to do. Later, you might or might not skip this step (and do it in your head), but it’s useful for the beginning programmer. You don’t need to write out the entire program, but you should design your data-structures and modules or functions. If it’s one of your first programs, you should hardly HAVE data-structures. You might instead write down the modes and loose flow chart between them.

Step 5: Code. Actually try coding your program. This is best done in an iterative way. My advice is generally to start with creating your core data-structures, and then the functions or methods that support them. Test each of these individually. Interpreted languages with a listener are the best because you don’t have to write test suites, but can just test the components as you go at the listener. Time spent debugging individual functions and groupings (say all the methods that belong to a data-structure) pays for itself 100-fold. I still do this. The less code you are testing, the easier it is to spot and find bugs. If you know that your functions are reliable (or semi-reliable) they provide robust building blocks to construct with.

Step 6: Debug. See above in “code” because they are heavily intertwined. Coding and debugging happens together in small loops. Again. The less NEW code you have to debug, the better. Debugging is hard for novices. Do not write an entire big program and debug it all at once. If you are using a language that syntax checks, check each function after you have written it. Fix the syntax errors (typos) and then test and debug the single function (or component of a program). Baby steps. Baby steps.

Step 7: Iterate and improve. Just keep adding things to your program to get it to where you want. Add a new feature. Improve an old one. Rip out some system and replace it. Add graphics. Upgrade them. Try to keep each of these changes as small as possible and test after each change. The longer it has been since it ran, the harder it will be to make it run.

_

I can not emphasize how important baby steps are. They are the key to avoiding fatal frustration. I have a law that helps define the size of subtasks: DO NOT EVER LEAVE THE COMPUTER IF YOUR PROGRAM DOES NOT RUN. You can take a piss or stretch. That’s it. I lived by this rule my entire programming career. You can’t always follow it, but try. Get your ass back in that chair. Mom wants you for dinner. Shrug. Your co-workers call you for a meeting. Snarl. I always think of a program like a car engine. You can sometimes merely tune it up, but a lot of times you have to take apart the engine to fix/add something new. That time when the engine is apart (the program does not RUN!) is very important, and should not be very long. If it is, you are not subdividing your tasks enough. I write all sorts of custom code to allow the engine to run again (even if in a half-assed way) while big changes are going on. These intermediate constructs are intended as throw-aways. But they save time. Having your program broken, writing more than a couple hours of new code that has not been tested, is a recipe for disaster. You could easily reach the point where you have no idea where the problem is. If you test in small bits as you go debugging is MUCH easier. Bugs are perhaps 80% likely in the most recently stuff. It’s the smoking gun you goto (haha) first.

You can do a lot with ASCII graphics!

A starter example of this whole process: My first game was a text based D&D type RPG game. I wanted to include a number of “cool” (to a 10 year-old) encounters. So I structured it as follows: There was the “character.” This was to be just a number of global variables (this is long before object oriented programming) like G (gold), HP (hitpoints) etc. I wrote a couple “methods” (functions – but they didn’t have names in BASIC, just line numbers) like “takes a hit.” This subtracts from HP, and if <= 0 branches to the “you are dead” part of the code (not really a function in those days). Then I wrote a number of “encounters.” These were the main flow of control in that program. It popped from encounter to encounter. They might be like: You have met an orc. draw orc on screen with text graphics (aka print statements). present options: “attack,” “run,” “use magic,” etc. wait for input and apply logic. If you are still alive send the player back to the main navigation loop (the place that doesn’t have a particular encounter).

That’s it. I expanded the program by doing things like: Adding more encounters. Adding resurrection as a pay option when you died. Adding an actual map to the main loop. Moving the “combat” logic from individual encounters into a function. Then adding to the character attributes like strength and dexterity which influenced combat. Beefing up character creation. Etc etc. These are all tasks that can individually be accomplished in a few hours. This is key. It keeps your program running most of the time. It provides good feedback on what you are doing.

The entire above “goal” -> “debug” loop can be repeated endlessly. Example: “add a save game.” You now have to save and restore the state of your player (various global variables). But to where? Disk presumably in those days. So you crack the BASIC manual and read about file I/O. First you go simple. There is one save game. It’s always named “adv.sav”. You write a function to open the file and write the vars into it. You examine the file to make sure it put them there the way you want to. You write another function to read the file. You add options to the game menu to call these functions. Then test.

Next baby step. Allow multiple save games. You add “filename” (or save slot or whatever) to the load/save functions. You hardwire it to something and test again. Then you add interface to the game’s main menu to specify which slot. You test that.

Iteration is king! Good luck.

_

Parts of this series are: [WhyThe SpecsGetting Started, School, Method]

Subscribe to the blog (on the right), or follow me at:

Andy:  or blog

Or more posts on video gaming here.

And what I’m up to now here.

So you want to be a video game programmer? – part 1 – Why

This post is a sequel of sorts to my How do I get a job designing video games. The good new is — if you’re a programmer — that nearly all video game companies are hiring programmers at all times. Demand is never satisfied. And the salaries are very very competitive.

The bad news is that it takes a hell of a lot of work to both be and become a great game programmer. Or maybe that isn’t such bad news, because you absolutely love programming, computers, and video games, right? If not, stop and do not goto 20.

I’m breaking this topic into a number of sub-posts. Although this is the intro, it was posted a day after the second, number 2, on types of game programmers, but I’m backing up and inserting this new number 1 (I’m a programmer, I know how to insert). Other posts will follow on topics like “how to get started” and “the interview.”

_

So why would you want to be a video game programmer?

Let’s start with why you might want to be a programmer:

1. Sorcery. First and foremost, being a programmer is like being a wizard. I always wanted to be a wizard. Given that magic (as in the D&D variety) doesn’t seem to be real (damn!) programming is the next best thing. Computers are everywhere. They’re big, complex, and all sorts of cool everyday devices (like iPhones, set-top boxes, cars, and microwaves) are really basically computers — or at least the brains of them are. 99.9% of people have no idea how this technology works. As the late great Author C. Clarke said, “any sufficiently advanced technology is indistinguishable from magic.” Yay computers! If you actually know the arcane rituals, incantations, and spells to controls these dark powers then you are… drum roll please… a wizard.

2. Career security. Computers are the foundation of the 21st century economy. Nearly every new business is based on them. Knowing the above incantations is secret sauce. All the growth is in high tech (product possibility frontier and all that). Hiring is supply and demand too. The demand is for programmers and other high tech specialists.

3. Even more career security. Programming is hard. It requires a big New Cortex style brain. This means lots of people can’t do it. It takes years of study and practice. I’ve been programming for 30 years and there is still an infinite amount for me to learn. Awesome!

4. It’s a rush. Creating stuff is a rush. Making the infernal machine bend to your warlocky will is a huge thrill. It never gets boring and there is always more to learn (related to #3).

5. It pays really well. This is related to #2 and #3. People need programmers and they can’t get enough, so they have to pay competitively for them. Even in the late 90s early 00s at Naughty Dog it was very rare for us to start ANY programmer at less than $100,000, even ones right out of school. Good ones made a lot more. And if you’re a total kick-ass grand master wizard (nerd) like Bill Gates or Mark Zuckerberg you can even start your own company and make billions. Take that you muscle bound warriors!

6. Solo contributions. You like spending time with machines and find all day dealing with illogical humans at least partially tedious. Sorry to say it, but even though most professional programming is done in teams a lot of time is spent at the keyboard. For some of us, this ain’t a bad thing.

7. Socialization. You need an excuse to hang out with others. On the flip side, because of this team thing you’ll be forced to socialize on and off between coding. This socialization will have certain structural support. This is convenient for the would-be wizard, master of demons but terrifying forces, but afraid of starting conversations.

So why would you want to be a video game programmer specifically?

8. Video game programming is really hard. Probably the hardest of the hard. It combines cutting edge graphics, effects, the latest hardware, artistic constraints, tons of competition, very little memory, and all sorts of difficult goodies. The really serious wizards apply here.

9. Other types. Video game teams have artists, musicians, and designers on them too. Lots of tech jobs don’t (although they sometimes have those pesky marking folks). Artists etc are cool. They know how to draw or compose cool stuff which makes your code look and sound much cooler.

10. Consumer driven. If you make it to work on a professional game they often sell lots of copies and people will have heard of what you do. This is much much cooler than saying “I worked on the backend payment scheme of the Bank of America ATM.” It’s so cool that it might even get you laid — which is an important concern for bookish wizards of both genders.

11. It’s visual. Seeing your creations move about the screen and spatter into bloody bits is way more exciting than that green text on the bank ATM. Talented artists and sound designers will come to you with said bloody bits and all sorts of squishy sounds which will make your coding look 1000x more cool than it would by itself. If you aren’t into bloody bits than you can work on a game where enemies explode into little cartoon rings. It’s all cool.

12. It’s creative. For me, I have to create worlds and characters. I’ve been doing so my whole life. Right now I’m not even programming but I’m writing novels, which is also about creating. Programming in general is pretty creative, but game programming is probably the most so.

13. Love. You love video games so much that working on them 100+ hours a week seems like far less of a chore than any other job you can think of!

I’m sure there are more reasons, but the above seem pretty damn compelling.

CONTINUED HERE with Part 2: “The Specs”

_

Parts of this series are: [Why, The Specs, Getting Started, School, Method]

Subscribe to the blog (on the right), or follow me at:

Andy:  or blog

Or more posts on video gaming here.

And what I’m up to now here.

So you want to be a video game programmer? – part 2 – Specs

…CONTINUED FROM PART 1.

There are a couple of broad categories of programmers working on video game teams. If programmer is your player class, then the following types are your spec. Programmers are all warlocks and mages so instead of “demonology” or “frost” you can choose from below. (NOTE: if you don’t get this joke, you don’t play enough video games) This is the real world however, and many programmers dual (or even triple) spec — i.e. they handle multiple specialties.

1. Gameplay programmer. Programs enemies, characters, interfaces, gameplay setups etc. Probably also does things like AI and collision detection. These programmers are sometimes a little less hardcore technical than some of the other types, but this is the sub-field where the most “art” and experience are often required. Learning how to make a character’s control feel good is not something you can read about in Knuth. It takes the right kind of creative personality and a lot of trial and error. In a lot of ways, this is the heart and soul of game programming, the spec that truly differentiates us from the more engineering programming disciplines.

2. Tools programmer. Works on the extensive tools pipeline that all games have. This is the only branch of game programming where you don’t absolutely have to know and breathe video games inside and out, and it’s a little closer to mainstream applications programming. That being said, life at most video game companies is so intense, you better love them. Tools programmers tend to be very good at practical algorithms, data processing, etc. For some reason, perhaps because it’s more “behind the scenes” this spec is often viewed as less glamourous and there are fewer programmers who want to go into it.

3. Sound programmer. A very specific niche. Here you have to not only know how to program well, but you have to care about the esoteric field of sound. You need the kind of ear that can tell if there is a one sample glitch in some audio loop, and you need to care if the 3D audio spatialization is off or the sound field isn’t balanced. This is often a fairly low level area as audio programming is often done on DSPs.

4. Collision programmer. This is a really specific spec, and often overlaps with Graphics because it involves totally intense amounts of math. You better have taken BC calculus in tenth grade and thought “diffy-q” was the coolest class ever if you want to go into this.

5. Network programmer. In this era of multiplayer and networked gaming there’s a lot of networking going on. And programming across the internet is a bit of a specialty of it’s own. In general, video game programming takes any sub-field of programming to it’s most extreme, pushing the bleeding limits, and networking is no exception. Games often use hairy UDP and peer-to-peer custom protocols where every last bit counts and the slightest packet loss can make for a terrible game experience. If this is your thing, you better know every last nuance of the TCP/IP protocol and be able to read raw packet dumps.

6. Graphics programmer. Some guys really dig graphics and are phenomenal at math. If you don’t shit 4×4 matrices and talk to your mom about shaders, don’t bother. This sub-specialty is often very low-level as graphics programming often involves a lot of optimization. It may involve coming up with a cool new way of environment mapping, some method of packing more vertices through the pipeline, or better smoothing of the quaternions in the character joints (HINT: involves imaginary math — and if you don’t know that that means the square-root of -1 then this sub-field might not be for you).

7. Engine programmer. For some reason, most wannabe video game programmers hold this up as their goal. They want to have created the latest and greatest video game engine with the coolest graphics. Superstars like Tim Sweeney,John Carmack, and even myself are usually seen as falling in this category. The truth is that superstars do all kinds of programming, and are often distinguished by the fact that we are willing and able to handle any sub-type and tie it all together (see lead below). In my mind engine programmers are jacks-of-all-trades, good at building systems and gluing them together. The top guys often blend with Graphics and Lead below. There’s also tons of stuff like compression (nothing uses compression like games, we’d often have 8-10 different custom compressors in a game), multi-threading, load systems (you think seamless loading like in Jak & Daxter is easy?), process management, etc.

8. Lead programmer. People also dream of being the lead. All the great programmers are/were. This is the hardest spec, and no one ever starts out in it. You need to be able to do any of the other specs, or at least judge what approach is best. You need to be able to roll up your sleeves and dive in and fix crap anywhere in the program. You need to live without sleep (4 hours a night every day for years baby!). You need to be able to squint at the screen and guess where the bug is in others people’s code. You need to know how to glue systems together. You need to be able and willing to trim memory footprints and optimize (no one else wants to do it). In fact, you have to know the entire program, even if it is 5-10 million lines of code, and you have to do all the crap that no one else wants to do. Plus, you often have to manage a bevy of other personalities and waste lots and lots of time in meetings. Still want the glory? Being lead is all about responsibility!

CONTINUED with Part 3: Getting Started

_

Parts of this series are: [Why, The Specs, Getting Started, School, Method]

Subscribe to the blog (on the right), or follow me at:

Andy:  or blog

Or more posts on video gaming here.

And what I’m up to now here.