Currently I am working on an inventory script to display the player's inventory using an array. I am having trouble setting a .amount property as I am encountering undefined errors when attempting to set them. Unfortunately, I am unable to utilize sets or hashmaps in this scenario. Can anyone provide some insight into what could be causing this issue?
For debugging purposes, I am presently using NaN.
//The array is already defined as 'inv'.//
var inv = state.history[0].variables.player.inventory;
inv[i].amount = 0;
//Loop through every item in the inventory.//
for (var i = 0; i < inv.length; i++) {
//If the inventory item is Apple, it should refer to ...inventory.Apple.amount.//
var q = inv[i].amount;
//If we encounter a duplicate in the array, increment the count and continue.//
if (inv[i] == inv[i-1]){
q = (q + 1);
//For the last or unique item, display it on the inventory screen.//
} else {
q = (q + 1);
alert(inv[i] + " " + q.NaN);
new Wikifier(place, inv[i] + " " + q.NaN + "<br>");
}
}