Tuesday, February 16, 2016

Too Many Quests? #gamedev

Check out that image above. I'll bet like me you are very surprised to see so many objects with exclamation marks above them.

How did this happen? Surely it isn't right? What do those plings mean?

I'll start by answering the last question first, and then in reverse order. Those plings mean that the object they are above has a quest for you to take.
They are not right. In fact only Chucky the Beaver in the middle of the image near his large stump home should have a quest to give you.
It happened because of a programming change I have made. It is an important one as it happens for a couple of reasons I shall talk about in a bit. The short answer to why do all these stumps have a quest for me is because they ALL think that they are Chucky. Personally I think they are delusional.

When I first saw this screen I was stumped (ta dah!) as to what had happened. Then it dawned on me that a change I had very recently made had caused this effect.

Going to the Code now...
In my code I have an enum array that lists ALL of the objects used in the game. I use a prefix like 'W_' for a world object (house, tree etc), or a 'C_' for a consumable (pie, apples etc). Lastly I have a 'S_' prefix for seeds. Here is a portion of my array. (the yellow NONE was not there previously).
public enum ITEM_IDS : int {


The way I knew how many elements were in this array was to use the 'END' for loops and creation of arrays to match this list. It works great for those kinds of things. However I also used it for an INVALID object ID. I need this as I have objects in the world that do not really need to be anything. Walls, some plants etc. So I set them to the default END and have been testing for that as an early out when a player uses an object for instance.

There is a problem with using an ID at the end of the enum array to mark my objects as nothing. That is when I add a new ID into the game it goes before the END... which means that any objects I had marked as END now think they are the new ID.. GAH! This isn't a good solution obviously.

The Fix:
I finally got around to fixing this in the last week. I created the 'NONE' as the first enum in the array and have set all my default objects to use that. It will not change no matter how many more IDs I add to the array. So no more fixing up IDs on objects in the game each time I add a new one. Phew.

The Down Side:
Well there was a down side. Adding the NONE to the beginning of the array meant that ALL my objects in the game IDs have been increased by one. So I had to go through every single object in the game and set them to what they should be again (I set them using the Unity editor and a public value). This will be the last time I will have to do it though, so that is a good thing.

Da Voodoochief

No comments:

Post a Comment