Not 100% sure if this will help you Vallar, but I've been messing around with crafting system ideas myself. This test project might be a bit too simple for what you're looking for, but it may give you an idea of how the JSON events could work if you wanted to go down that route. Depending on how many crafting ingredients you have, you could probably swap out the Global Variables for an Array, but I've not gotten that far yet.
Ignore the filename, the project started as a drag/drop thing, and I've not gotten around to renaming it!
Crafting Test Project
Thank you very much Laura for sharing it. There are a few key differences between what I saw in your project and what I am attempting to make:
- In my crafting system the player can slot the ingredients in any order. So before hand I have no idea what order the player will slot the ingredients in. So that requires that I loop over the ingredients in a recipe and check each ingredient separately. This is why I add all my ingredients to an array as — suggested.
- In my system, there aren't a set amount of slots to craft from. For example, right now the player has 5 slots to fill (the number of slots was completely arbitrary) so this may change in the future and the system needs to adjust for this. It could be 8 slots available or only 3. Either way, while that isn't a big deal, not all recipes use all the slots. So right now while I have 5, some recipes have 3 or even 2 slots only used. Some have the full 5.
- In my system each of the ingredients have a specific count and if that count isn't available I can't craft. Example 10x wood + 5x stone + 50x iron will make an Iron Breastplate (absurd ingredients but it is for the sake of example). So I need the recipe to have that kind of data so I can check if the player has that amount or not.
What your .capx showed me however is that I can loop over "recipes", I wonder however how can I loop over a list of ingredients INSIDE one of the recipes? Would it be same for each but instead I do something like "recipes/ingredients"? In that case, is there an action in the JSON object that can quickly tell me what the current ingredients count without manually iterating and adding 1 to a local variable that counts them?
Like let's say I have this JSON:
{
"recipes":[
{
"recipeName":"Blinding Flash Potion",
"components":[
{
"name":"Wormwood",
"count":2
},
{
"name":"Sulfur",
"count":5
}
]
},
{
"recipeName":"Potion of Sweet and Savory",
"components":[
{
"name":"Salt",
"count":5
},
{
"name":"Sugar",
"count":5
}
]
}
]
}
How do I then check the "count of components" without iterating? How to then iterate over Components for ONLY the potions that match the "count of components" I am targeting? How do I iterate over those components to confirm the name matches and then grab "count" to deduct what I want?
Sorry for the wall of text but these are the issues that I ran into with JSON and I wasn't able to resolve/answer them.