The Space Game 2: Inventory

It’s been a long time since my last entry. Partly because I had other, non fun stuff I’ve been working on, and partly because I got stuck on the inventory system. You can see the results below, and some thoughts and conclusions after the break.

invscreenshot

It doesn’t look like much, does it? It took awhile though. I wanted an inventory system that worked more or less like the ones in hack ‘n slash ARPGs. I thought it would be a simple thing to do, but it didn’t turn out that way. A few lessons learned:

Have a detailed plan of how you want your feature to work. I messed around with different click combinations, etc, which caused me to make changes to the code that made it messier and messier.

– Study the classics. The way I finally found a good, intuitive system was by bringing up every ARPG in my Steam account (Titan Quest, Torchlight, etc), and studying their systems and taking notes on how the interfaces work.

– Premature optimization is the root of all evil. This was actually said by Donald Knuth, a famous computer scientist who’s ridiculously smart. And it’s true. Often your code gets hairy when you make it overly complicated in an attempt to make it very efficient. I fell into this trap by doing all sorts of stuff that was supposed to minimize the number of GML objects used for the inventory. What I got was a hairy mess of code that was next to impossible to debug. And the more bugs I fixed, the more complicated the code got. The best approach is to do most of your optimization after the basic code is in place; then you can experiment and see where the performance improvements are really needed.

– When something’s terrible, throw it out. I went on trying to make awful code work, but in the end the best solution was to make a new solution that made sense. You don’t want to throw out stuff all the time, but at some point you have to get rid of code when it’s just the wrong path to take.

Next on the agenda: Some improvements to inventory, then on to the loot system!

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s