Another nasty bug fixed

I spent the last 3 days with a nasty bug, I almost went insane…

When opening a chest, the loot normally goes into the visible character’s (currently selected) inventory.

But if this character’s inventory is full, then the game will find the next character with enough room in his inventory.

The problem appeared when the next character had more then 6 items already in his inventory. The game tried to shift every item in his inventory to the left, so the new item will be the one selected, this way the player can see instantly the last looted item when browsing the inventory.

Everything stopped, nothing worked when clicking, the game just stuck.

The problem was so simple, that I’m embarrassed I wasted so much time on this bug… It was a simple do-while loop that never ended, infinite cycle.

The problem was that Unity started the do-while loop faster then Debug.Log function calls, so even if I put 20+ Debug.Logs before even entering the function that handles the opening of the chest, to see where it goes wrong, it wouldn’t show anything at all. I had no clue in which function was the problem (have 100+ functions already)

Oh well lesson learned, always check while and do-while loops if everything stops 😛

I tried to implement random generation of enemies (now it is static, same enemies appear in the dungeon rooms) but all I could think about was this bug… Now that it’s fixed I can continue with that 🙂

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