Tuesday, February 2, 2016

Improving Code because of bugs

So here I am fixing bugs when I realize when testing that I have a major bug. This one happens when you drop a quest.

You see some quests give you an item to deliver, such as a Note to deliver to Aaron from the Mayor. Now this quest had some special code to give you the Note in your inventory when you pick up the quest. It also has some unique code to handle removing the item from your inventory when you complete the quest.

The bug was that when I chose to Drop the quest this did not have any special code to remove the item. So I was left with the item in my inventory... then if I picked up the quest again I would end up with Multiple of the quest items.

When I was looking over the quest code I realized that I already have a lot of Unique code to handle all these quests that include items. hmm, perhaps there is a better way?

YES, there is a better way. I can include the Quest item in the Quest setup data. Perfect I reckon. I can just use a standard bit of code to handle the giving and removal of the quest itmes into your inventory. Then if you drop the quest the same code can easily tell there is a Quest item associated with the quest and remove that.

Well I did it, and it works GREAT!  This is one of those times where finding a bug allowed me to remove a whole bunch of code and write a much better set of code instead.

G'night,
Da Voodoochief

No comments:

Post a Comment