Saturday 23 November 2013

The day the Bluff Cave became the Bug Cave

An obscure reference to an obscure reference

One thing that makes Asciilands so different to any other software I've worked on is how the bugs manifest. This comes from the fact that Asciilands is creating a "world" of sorts to reflect the real world. This means, like in any other game, that you interact with it bringing with you certain ideas of how certain things should work, e.g., you expect to be able to walk on sand but not on water, you expect to be able to open a treasure chest and if you can't, you expect that once you find the key you will be able to. This effect, however, is not limited to the player. I, as the developer, bring with me expectations of how things will happen when things go wrong and like the player, when the disparity between my expectations and what happens becomes too great, it feels weird.

The software I've worked on for my paid jobs have had bugs to be fixed but these bugs are generally things like "Oh dear, this column is not sorted correctly!" or "This thing stops happening after about 20 cycles or if you click in this region." or something equally benign. The bugs are equally simple / complex but that jolt that you get from something unexpected happening is greatly exaggerated when it happens in a piece of software that's supposed to be reflecting some kind of other reality, not just displaying some stuff.

For instance, a stray reference making something incorrectly identify another object as its parent would maybe cause a piece of data to render on the wrong tab in normal software. In Asciilands, it meant that when I tried to equip my silver axe, nothing happened...it just disappeared. "That's weird" I thought but then when I went into the cave, I saw that the torch in the cave was holding my silver axe.

This is obviously a ridiculous situation but the only thing that makes it weird is that it makes you visualise that event in a more human way. You see a little dude pulling an axe off his belt only to have it turn into a puff of smoke then you can imagine his confusion as he sees it being wielded by some other inanimate object in a cave somewhere.

This unique way that a game can give interesting, and sometimes entertaining, kinda "narrative" life to basic reference error bugs is what makes Asciilands fun to continue working on where other projects might just be frustrating.


The simple change

There has been an annoying little oddity in Asciilands from the very start and that oddity is this: when you change maps (e.g., go through a door or get teleported to a new place), the browser refreshes itself automatically. This is because when you log onto Asciilands, the map that you start in loads itself on the server then sends all the information required to display the map to the browser as JavaScript objects. These objects make up all the tiles and scenery and monsters and items etc. That way, when we update the frame, we only need to send back single letter codes for each asset instead of about 170 letters for all the html required. That's 99.52% more efficient than just sending the raw html but it comes at that cost; that annoying browser refresh whenever you go anywhere. Or at least, it did.

After thinking about how I was going to do it for a while, I sat down and started making a few of the changes required to get it happening.

I made the changes and it didn't work at all. This is my life.

The bugs I encountered while trying to make this fix were sometimes a little creepy but mostly just amusing so I thought I'd capture a bunch of them to share for those who might be interested.

First thing was to make the new starting position near a place conducive to testing: the entrance of the Bluff Cave. Here we are:


Lovely! Now let's head into the Bluff Cave and see if my modification works as seamlessly as I'm hoping!




Hm...I guess not.

Ok! Learning experience right? We can see that it at least made an effort: We have that darkened square that makes the cave dark so it kinda knows it's supposed to be dark, it pushed the view down and tot he right so that it would be centered if it were smaller (like it should be in the cave) and the thought event was triggered ("The air is cold" seen on the right hand panel).

What do we have? It seems to know we went into the cave but it's not letting us stay there...or something?

Ok, let's try this:


So far so good...


Ah. Ok, that's not right. Last time I was in here I was being chased towards the ladder by a zombie; not being chased towards the pile of presents by the poisonous sword.
At least it knew we were in the cave, though right?

What could have done this? The tiles are ok but the sprites still seem to be from the old map. I don't really get it but maybe if we head back out, the old map will have the cave sprites? It's not impossible...


It's...oh god what? Ok so everything is either on fire or made out of gold and banner items. Also did the door to the cave turn into a red present? What's with presents appearing in all the bugs?

Refresh!


Strange: refreshing fixed it without having to do any kind of data reset. This means it's a javaScript issue! Things not being sent properly or sent late or sent sideways or sent in the wrong order or something? There's a miscommunication; time to try a few more things...


Ok, this is new and much closer to what we wanted! We have the cave and the zombie...but the cave is blue. Why are you blue, cave? Are you hinting that you want some kind of underwater cave section?

Wait a minute...the wall is blue...like the water. 'W' makes sense as a tile key for both Wall and Water! Wait, why does that even...AH!

This should be it:


...aaaaaaand...


Hurrah! Everything's exactly how it was five hours ago except that the page doesn't refresh [almost] unnoticeably when you enter the cave!

Still more exciting than fixing sort order or grid alignment, right?