Item Display Menu
Author: Jymeer Wilkins
Problem:
The problem I ran into with the item menu was a index problem with the for loop. I would store all the items that the player picks up into an array, but I didn't want to add each individual item in the display. For every duplicate item in the list, I would increment an integer. So, in the display, there would be the item, and a number showing how many the player had of that item. would loop through the list to get each item in the list, and for loop through the list again to check each item. If the item I was checking was identical to the item I was currently on in the first loop, then I would delete that item from the list so the same items wouldn't get checked twice. Then I would increment the number. The problem I was running into was a problem with the indexes. Since I was deleting items from the list, it would mess up the last index of the loop. It would make the loop end earlier than it needed too.
Solution:
I struggled with this problem for a bit, because I didn't exactly know what was wrong. I picked up all the items, and stepped through the loops to see what the problem was. Once I realized why the loop was ending early and not going completely through, I kind of already knew how to fix it. I took the length of the array that was passed into the function and stored it in a variable. Then I would set that variable as the last index for the loop. This made it so the last index wasn't continuously changing. This fixed my problem.




Comments
Post a Comment