I have a series of crafting scripts that have a history of making the wrong item on occasion, derailing the script. I think this is a product of trying to optimize speed. This also caused issues clearing items out of the backpack since the items that were getting made were pretty random. For several months I have been trying to come up with a solution that will allow me to maintain speed and efficiency, but detect the random items to tell me when to reset the process. A secondary concern is getting the random stuff out of the backpack.
I finally came up with a solution today that involves taking an inventory of IDs of the items in the backpack at the start of the script and capturing them in a variable. I am using it as a check against items I make to confirm correct make, and to keep from throwing things away. It's pretty simple, but I figured I would share since it took me so long to figure it out.
Finditem * C_ , #BackpackID
Set %BackpackItemString BackpackContents:
For #Findindex 1 #FindCnt
{
Set %BackpackItemString %BackpackItemString , #FindID
Set %BackpackItemString %BackpackItemString , _
}
The second line inserts an underscore between IDs to avoid the extremely unlikely occurrence of an ID getting duplicated with parts of other IDs.