Hi everyone! I’m encountering an issue where my crafting system allows a recipe to be crafted even if only one ingredient meets the required conditions.
What I’m doing wrong here? Preview Video of the Issue
Some Context S_Slot Structure:
Item_ID (Data Table row handle)
Quantity (Integrer)
Category (Enum)
Recipe Variable is a Structure with:
Crafteable (S_Slot)
Ingredients (S_Slot Array)
Recipe Set:
Recipe variable is set when I click in the recipe. I use the same logic for setting the widget Icon, text and color change.
maybe im not connecting the dots correctly from your different screenshots but it looks like once your find item macro is finished, it moves to add the item (can’t see whats happening there, if there’s a check that happens, but if there isn’t then it’ll add the item). So potentially you just need to add a check there, but probably not because your code is quite organised I doubt you’ve overlooked that… but I’ve seen it before haha
Didn’t understand very well what you meant.
I didn’t show the function but “Add Item” only happens after the second loop is complete and “Can add Item?” is set to true.
Quick overview 1º Set “Can add Item?” to false 2º Set “Can craft” to true 3º The First loop ( Find Items Macro) checks Inventory and store Quantity named “Current quantity” and row name “Consumables Row Name”. 4º The Second loop ( Qeue Ingredients Macro) Checks ingredients and store Quantity named “Needed quantity” and row name “Ingredients Row Name”.
Branch Checks: 5º Next I check if “Current quantity” is < than “Needed Quantity”
If it’s true set “Can craft” to false
If it’s false Continue
6º Next I check if “Consumables Row Name” is == to “Ingredients Row Name”
If it’s true Continue
If it’s false set “Can craft” to false
(I think my problem is probably Between step 1º to 6º.)
7º Remove ingredients from inventory 8º Set “Can add Item?” to true 9º If second loop is complete and “Can add Item?” is true, then trigger “Add Item”.
Yeah, what Deep Pixel said I think, except don’t remove the set Can Craft before the loop, your logic requires that.
You appear to have other problems in waiting though, hard to say for sure with all those nested loops… But you appear to be removing the ingredients in the loop, rather than after, so (once the current problem is fixed) anything found will be removed, even if the craft ultimately can not proceed because something else is missing.
but you don’t appear to be checking if you Can Craft before calling Add Item, unless that is happening in Add Item? As is, Add Item is being called after the loop, always, if it is not checking Can Craft then that is your error.
Didn’t undertand also, sorry, can you elaborate?
But just to show why I think my problem is before.
For some reason the logic knows wich item not passed and still procced with the logic even if I set “Can craft” to be false if the values doenst match or the names are not equal.
I also tried to instead of use a nested loop, “Get a copy” of ingredients array and run the array by using the array element of “Find Item” loop but the problem still the same.
Yeah, like Silnarm says, nested loops can get tricky. More or less the very last looped item is setting the final value of ‘can craft’ as far as I can tell. (So it check if you have enough bananas, you don’t, it sets it to false… then it loops again and checks the next ingredient, seems you do have enough of it, so it sets it to true… thus ignoring the concept of checking for all ingredients.)
I suggest altering your condition to have an AND bool involved so it requires having each ingredient to the correct quantity. You could have a temporary array for each ingredient (or just use an int array and each index refers to a different ingredient - therefore only need 1 temporary variable) then you could just loop that info into the array so that once the looping is done you can check the quantities of each ingredient, instead of the last one queried.
Consider using a map<ItemID, MyStruct> in the inventory to avoid nested loops.
In regards to the bCanCraft: If all ingredients are needed to craft, then on the first failed condition simply return false. If the loop is allowed to end, then return true: