Category: programming

About my process

One thing that I think I am starting to realize about my programming process is how important it is to me to be able to complete a task in a single session.

Each evening when I sit down to work on my game project, I don’t usually have a specific idea about exactly what I want to work on or accomplish. I do have a lot of general ideas. I have a list of things, a backlog of features that I have brainstormed but have yet to implement, or have yet to implement to my complete satisfaction, and a rough idea of the priority I’d like to give on each item in that list. When I sit down to being my development session, I review the list and pick something. As I continue to develop, I continually update the list, usually removing things from it that I’ve completed (it makes me happy/inspired to see the list shrink), but sometimes adding new things if an idea comes to me or I realize a new problem has come up as a result of something I’ve been working on.

I am not strict about working on items in priority order. To some extent I am taking things in order of importance, but mostly I try to work on the most important thing that is also easy to accomplish quickly — the so-called low-hanging fruit type stuff that is easy to do and provides a high value to the project. To a larger extent, I work on things in the order that I can work on them — some things are dependent upon other things and I have to do those things first in order to be able to do the next thing. Or sometimes I need to learn more about something in order to do it, and doing something else first will give me the opportunity to start to get into that topic in a more lightweight and manageable fashion.

Sometimes I just work on something that I happen to be interested in at the moment — it is important to recognize the power that having an interest in something has. If you’re interested in something, engaging with it is easy and natural. If you’re not interested in something, it’s hard. If you’re actually interested in something else, it can be all but impossible.

Having a sense of progress and momentum is extremely important to maintaining my morale and motivation.

I like to work in long, mostly uninterrupted sessions. I’ll start around 6-7pm and stop around midnight-1am. I don’t just work on the project during this session, though — I read my usual websites, do email, make dinner, chat with friends over IM. I find that this does not interfere or impede my progress or ability to focus, and any of these “distractions” makes for a good punctuation mark that allows me to take a breather and come back to the project with renewed energy.

I don’t even spend most of my project time developing and coding. The coding part of the work just doesn’t take that much time. I spend more time building and playing, then going back and tweaking something, building, adding a tiny little bit, and replaying, again and again, until I get what I wanted, or, often, figure out what I wanted. A lot of times, an idea I had at first is not really as good as I thought once I have built it, but something else that is close to that is better. By carefully testing each little change iteratively as I build, I ensure that I move in a steady direction toward a successful design. This is much better than trying to design everything out on paper before I put any time into building it, by far.

When I first sit down to work for the evening, I have in mind a goal to improve some aspect of it, and by the time I am ready to put the project down again, leave the game in a state where it is both playable and improved from the last iteration. I sit down and look at my list, mull things over for a bit, do a little bit of planning and thinking, and then start building. As I build, I document what I’m doing.

The first thing I do with each session is to create a new version of my project. I don’t stop working until I’m satisfied that what I built works the way I wanted it to, and results in a better game than what I started with.

I’m not sure how sustainable this is, this approach of having tiny tasks and completing them in one session, but as much as possible, I want it to be. I find that I am far more productive in my project as I am working if I can complete* some aspect in one sitting, as it were. If I don’t make it, I run the risk of losing my thought process and not being able to pick up where I left off. I think of it like writing a book — you don’t want to just cut off in mid sentence. And ideally, you’d like to be able to complete a chapter, or at least a thought.

*When I say “complete”, I don’t mean “final”. I will likely go back again and make further refinements when the time is right. For example, when I started implementing my enemy objects, at first I just placed them into the game as immobile objects. I next focused on interactions with the player object. In a later session I added very basic movement, and spent a lot of time tweaking that. In upcoming sessions I plan to further refine enemy movement, adding different modes and coming up with some AI routines that determine how the enemy “decides” what mode to be in depending on what’s going on in the game.

My guess is that if you architect your program the right way, you should always, or nearly always be able to use this approach of tiny steps over many iterations. To extend the architecture metaphor a bit, if you’re laying bricks, to build a bigger building you just use more bricks — you don’t suddenly have to switch to bigger bricks that become unmanageable for one person to wrangle. That may not always hold true, but my feeling is that it should most of the time.

GameMaker 8 bug in TestVariable action?

I ran into a bit of strangeness with my game project today. While testing a feature, I noticed something inconsistent in the way the program behaved. Upon investigation I discovered that the cause of the inconsistent behavior was that I used two different functions to do a comparison of a certain value in two different calculations, and these functions are not equivalent.

In GameMaker 8, there’s an Action called Test Expression, as well as an Action called Test Variable. It turns out that Test Variable isn’t so good when it comes to testing for equality, due to the way GameMaker handles typing of variables. For the most part, there are only two types of variables: strings and real (floating point) numbers. But in GameMaker 8 they also introduced a few new functions that return integer values. It turns out, if you use Test Variable to compare the value of a real number to the value of an integer to see if the two values are equal, Test Variable will never return true. However, if you use the Test Expression action to do the comparison, it will return true.

In most programming languages, it is impossible to directly compare an integer to a floating point number; you have to use type casting to convert one of the values and then do the comparison. Working with floating point math is tricky with computers, because of rounding errrors, where values are often +/-0.00…01 (whatever the precision is) off due to the way floating point math works. Yet, GameMaker does not display the full precision of the floating point number that is stored in a variable — it only shows the first two decimal places, and hides the rest. Thus, to GameMaker’s Test Variable action, the number 3, which might be returned by the irandom(n) function, is not equal to the real value 3.00.

Test Expression does get this right, though, and automatically accounts for the rounding error, and will consider int 3 to be equal to real 3.00(00…01).

Hopefully they’ll fix Test Variable in a future release. I have reported the issue to GameMaker’s bug tracking system.

Developing in GameMaker

One of the first things I did with my gmk project is figure out how to do file I/O so I can write out to an event log so I can see what’s going on in the game. This is highly useful, since it allows me to track every action that happens, every value of every variable if I want to.

Once I figured out how to write a file I/O routine in gamemaker language, I put logging on a bunch of things in the game that I wanted to track so I could see it working and make sure that it was working the way I wanted it to. Mostly this was a check to verify that the way I understood the environment to work was correct.

After I’d written a logging routine on just about everything I’d built so far, I discovered that you can call scripts. So I got excited by the prospect of being able to write a reusable script that would save me from having to write out the same code again and again, like I’d just did. So I built my script, proved it worked, then went and ripped out all that redundant work that I’d just put in. I didn’t mind at all because it meant moving forward that I’ll have a lot easier time with building up code, and I’d discovered it way early in the project.

(I probably could have learned it even earlier had I read the manual cover to cover before starting, but I find it easier to engage with something if I play with it as I learn and read as I play with it whenever I get stuck.)

###

The next interesting thing I did was a feature I wanted to implement early. Trying to do the early stuff the right way is important, but you can’t second-guess yourself so much that you don’t make progress at all because you can’t decide what approach is truly best.

The feature in question has to do with the graphics. I wanted a way to graphically show the relative strength of the enemies to the player. Basically, we have a “strength” variable, and if you compare it to the player’s current strength, an enemy is either weaker, equal, or stronger than the player. I want to make this apparent to the player visually.

On my first development iteration, I simply implemented a separate object for weaker, equal, and stronger enemies, which all inherited from a base enemy class.

On my second development iteration, I figured out that I could have a single enemy class, and for the initial value of the strength variable, I can just assign a random number, and then based on this random number, compare it to the strength value of the player, and assign the appropriate graphic to the enemy. I got this to work pretty easily, and it eliminated the need for having separate objects to represent the weaker, equal, and stronger variant enemies. This might be a mistake, as it might make things more complicated to have a single object doing all three things. But I think it is the right way for now.

On my third development iteration, I needed to make the enemies update their graphics. The player’s strength increases during play, so as the player’s strength changes, the enemy’s relative strength might change from stronger to equal, and finally to weaker. I wanted to figure out a way to do this efficiently, and figured that having an event that fires whenever the player’s strength changes would be a good solution, and the “right way” to do it. I haven’t been able to figure out how to do this in GameMaker yet, however. It’s not an easy thing to do, and probably requires a bit more understanding of GML than I have at present. GameMaker handles instances of objects in a kindof kludgy way, and this quirk in the way the language works makes it harder for me to do what I want to do.

After trying to figure it out for about 4-5 hours, and not getting anywhere, I opted to go for something cruder but simpler, and found that it works just fine, at least for now. Rather than trying to fire an event that checks the relative strength of every existing enemy in the current room whenever the player’s strength changes, I simply created an event for the enemy class which checks its strength relative to the player each and every step of the game engine, and updates the enemy’s graphic. Obviously, this would not scale as well (I’m basically “polling” the objects 30 times/second, instead of simply calling a method as needed, which would be a much more efficient way of doing it.) So this approach may not work out so well if the game gets larger. But at the scale I’m currently working at, it performs just fine. I’ll have to revisit at some point if I have too many objects in play, but I’m not going to worry about that for now.

Game project

So I’m working on my first serious attempt at a GameMaker project.

The thing with working personal projects is balancing how much you talk about your project with how much you work on your project. You can’t be all talk and no action, obviously, and you probably shouldn’t simply spring a new project on an unsuspecting world, either.

I’m not yet sure how to do this right. I don’t want to spend a bunch of time describing something that doesn’t exist yet, especially if I may change my mind about particulars a bunch of times before I decide to release it. On the other hand, not talking about it just drives me crazy. I’m into my project, and it’s interesting and exciting to me, and I just have to talk about it.

The other thing that’s hard about talking about working on personal projects is talking about it with a proper level of authority and confidence. I’m doing things that are new to me, for the first time in many cases. But most of what I’m doing is technically not all that difficult or sophisticated. As much as I want to be excited about figuring out something, I don’t want to make myself look dumb by blogging things that are the equivalent of what “Hey, guess what I just figured out? When you have a plus sign between two quantities, that means they’re added together!” would be to a math blog.

What I do like about this project so far:

  1. The fact that I’m doing something that I’ve wanted to do my whole life.
  2. The fact that I can do it.
  3. The fact that I am doing it.
  4. That the progress thus far has been fairly steady.
  5. My process: planning, building experimentally, testing, documenting. I feel like I’m going about this in just the right way.

In fact, I really like my process. Here’s what I do:

  1. Sit down and think about what I want to do. Brainstorming. Create a list, prioritize it. This becomes my backlog.
  2. Work an item on the list until it’s done to where I’m satisfied with it for now. This involves building and running it to test it, over and over. I try to conceive of my solution first, then build it, starting small and simple, and building off of what I just did. I’m more tentative with things I haven’t mastered yet, but that’s the natural way of things.
  3. Write up what I did in my version history. Update the backlog, to either remove the item from the list, or more likely, update it to reflect the next level of refinement that I want to get to with that item.

So far, so good. I have a ways to go yet before I have something that’s worthy of an alpha release. I might have it out in a few weeks, we’ll see. What I have right now is playable, but not interesting as I’ve yet to implement any enemy behavior. I expect that the enemy behavior will be very interesting to work on, and probably one of the trickier aspects of the game and thus may take me longer than what I’ve done so far.

Success!

It’s time for a catch-up for my neglected blog…

What I’ve been up to lately: The Computer Game and Simulation Design class wrapped up this week, and I both did extremely well in it and enjoyed the class very much. I ended up carrying a 101.5% average in the course.

I pwnd CGSD120!

My grade for CGSD 120

Since I now have some spare time with the class out of the way, I’ve started my first independent project. I’m not really ready to talk about it in depth just yet, but in the next few weeks or so I hope to get it to a playable alpha state, and then it will be made available over on the releases page.

DomeWrinklesCurl 1.1

I’ve released an update to DomeWrinklesCurl. This isn’t really much of a game still, it’s just a simple rock-paper-scissors programming exercise for Win32 CLI console.

The new feature in this release is improved stat keeping.

With this release, I’ve also cleaned up the code a little bit. The initial release ran OK, but internally was a bit messy. Not a big deal, you won’t notice unless you look at the source and compare it to the 1.0 release.

I’ve been thinking of ideas about what I where I want to take this project…

2.0 branch:

  1. Sound effects
  2. Colored text
  3. Select # of players (0-2)
  4. Named players
  5. External configuration file for settings, game stats to persist

future branch:

  1. 2-player network play

Once I get this much done, I’ll have enough of a framework developed to begin building a real game with, and I’ll start moving from the Console to GUI.

Download it here:

dwc.exe (zip archive)

dwc.cs (source)

DomeWrinklesCurl 1.0

I wrote a windows console game in C# as a programming exercise.

It’s nothing spectacular, but it’s my first game, and I’m happy with the way it works.

The game is a silly pug-themed implementation of Rock Paper Scissors that I made up, called Dome Wrinkles Curl.

The rules:

  1. Dome straightens the curly tail.
  2. Wrinkles cover dome.
  3. Curl wags away the wrinkles.

Download it here:

dwc.exe (zip archive)

dwc.cs (source)