I have been trying to loop over a scriptable object (the orderList) to determine if an item (included in the orderList) can be delivered (which means, if for a specific job, the craft time allocated is enough to have the item created). The problem is that I found out that the second item in the orderList was always missed while looping over and I can't identify why.
I checked the parameter of the second itemObject and the attributed job is correct, as well as the craft duration. I added a debug log to check if the if condition rejected the item, but it seems that the function does just not loop over the second item, and goes directly from orderList.Container[0] to orderList.Container[2].
Does anybody have an idea on why the second item is ignored?
Here is the code for information:
foreach (var job in Job.GetValues(typeof(Job)))
{
Debug.Log("job: "+ job);
int duration = 10;
for (int i=0; i < orderList.Container.Count; i++)
{
Debug.Log("item: " + orderList.Container[i].item.title);
Debug.Log("pre-duration: " + duration);
if ((orderList.Container[i].item.métier == job.ToString()) & (orderList.Container[i].hour <= duration))
{
duration -= orderList.Container[i].hour;
Debug.Log("post-duration: " + duration);
inventory.AddItem(orderList.Container[i].item, orderList.Container[i].amount);
deliveryList.AddItem(orderList.Container[i].item, orderList.Container[i].amount);
orderList.RemoveItem(i);
}
}
}