I made an attempt to refactor and simplify the example, as well as allowing it to be more flexible in terms of number of ingredients, and ended up redoing it in a way that made more sense to me. Maybe this might be of use to you.
dropbox.com/scl/fi/cg7xje8s2lw9tq063uicx/dragdropcraftingexample.c3p
Instead of using global variables, there is now a second array to keep track of matching ingredients, which allows for recipes of any size. This array is also used to delete the used ingredients by UID, so the instance variable that kept track of "used" is no longer necessary either.
The overlap array now keeps track of both the item id and the UID of every overlapping item, so that each individual instance is kept track of.
The JSON format for the recipes changed a little to make it more flexible as well. The ingredients list is now stored in an array inside an "ingredients" object, which can include as many ingredients as you want, without having to define id1, id2, ect.
So it looks like this now.
"recipes": [
{
"ingredients": [0,1,2],
"result": 3
}
]
Edit: Updated the example so it shows how to load json from multiple files, since I would personally keep them separate in an "items.json" file and a "recipes.json" file.
Note that recipe matches are currently prioritized by first valid match. If I were to improve on it I would probably design the crafting system so that the order of the recipes in recipes.json doesn't matter. Basically account for conflicts to prevent situations where there may be two valid recipes ahead of time (such as defining what happens if you have a and c overlapping already, and drop a b onto it when you can have the recipes a+b=c, and a+b+c=d).