Comparing objects and organizing meta data

Okay, before I say anything else, I'm trying to brainstorm the best way to tackle a Trial-and-Error Crafting system (where the player punches in items to mix, instead of selecting a recipe from a menu).

I know it's a pretty tedious type of system to set up, but regular crafting and synthesis systems don't achieve what I want--- which is multiple combinations resulting in the same outcome. For simplicity's sake I am crafting Items only with Item ingredients, so no weapons or armor to account for.

So far I've tried a few things, mostly focusing on writing stuff into item noteboxes. I was thinking of having recipe ingredients defined by notetags arrays instead of Item ID numbers.

All cookable/craftable items have a recipe tag (like for a veggie omelet, <recipe:vegetable,egg>), and the game extracts the meta.recipe key by splitting it into an array and sorting it (so you'd get ["egg","vegetable"]).

When you are selecting ingredients for a recipe, it pushes their <kind> key into an array.

So you may select a spinach/pepper/etc with the tag <kind:vegetable> and an egg with the tag... well, <kind:egg>

And when you confirm your selection, the array sorts (to ["egg","vegetable"]) and then checks to see if it matches any valid recipe. Which it should, and the result is veggie omelet.

So far, I can get this much to work, at least by tinkering around in the console window... but it's pretty simple, and not without flaws.

Problem time:

What would have to be done if a recipe needed more specific item values? Like a strawberry shortcake that MUST have a strawberry to make, but the strawberry item is tagged as <kind:fruit>... in that instance, it would be better to use the item's ID instead of a notetag, or at least allow the tag to have multiple values, like <kind:fruit,strawberry,...>

So at this point, I have to rethink how the <recipe> tag is set up (or the <kind> tag?? dunno what I should be looking at), and then figure out how to get the right kind of info from the ingredients and recipe requirements to line up.

What are the best (or at least better) ways to go about doing this?

edit: I found this http://snook.ca/archives/javascript/testing_for_a_v (using "in") which looks like it's sort of in the direction I want, but I'm not really sure how to use it effectively, or if it really is what I want to do or not.

It still wouldn't fix the problem of me not knowing how to organize notetags properly, in any case.

edit edit: one possible solution to the strawberry cake problem might be done through the <recipe> tag... I figured out how to convert an array of strings to a mixed array of strings and integers. When the script tries to match ingredients to a recipe, there could be a special case when the recipe calls for an integer and it searches the ingredient item's ID instead of the notetag. It's still not a totally satisfying solution, but it's better than before. I just have to figure out the correct sequence of events.
 And when you confirm your selection, the array sorts (to ["egg","vegetable"]) and then checks to see if it matches any valid recipe. Which it should, and the result is veggie omelet.
This is just a thought, but you could have a tag for specific ingredients, or perhaps something like: <kind:fruit, strawberry> like you said, and split it into an array. 

Then when you want a more specific recipe.. <recipe: strawberry, flour > you take the second key, instead of the first.

Code:
if(item.meta.kind) {//Check for kind ^//split kind into an array with two values separated by commavar array = meta.kind.split(",");console.log(array)}
Hmm, that's true. I'll have to see if I can get that to work. There would have to be a simple way to define in a recipe whether it's looking for something general or specific though.

But for now, I think I'll go with the string-and-integer method and see if it's appropriate for all the recipes my game. If everything works I may release a plugin, and then worry about how to improve it.

The other thing I thought of was using eval to split up the recipe requirements tag into an object (that way, it may be possible to have complex requirements like "any fish with a price of over 1000g"), but I haven't had the chance to reflect too deeply on how to implement that.

Edit: I also realized that with some extra setup, using eval would make it possible to have optional ingredients as well. It wouldn't actually do anything, but if it was integrated with something like Yanfly's item core it could be possible to make unique items...
That's  interesting; I honestly think objects might be the way to go, because the arrays could get kind  of messy. The object idea would be easier  to read and manage I think. I'll take a look at eval. You said it creates objects? In that case, I think the only thing that may be an issue is how you want to handle those optional ingredients.

Original thread: https://forums.rpgmakerweb.com/threads/comparing-objects-and-organizing-meta-data.54590/