Hello Community,
I am am making a crafting system. What I am doing is getting the item IDs that are in the crafting slots and putting them into the ingredients List. Then I am checking to see if the ingredients in the database are equal to the ingredients I have in the crafting system.
I have been at this for a while now. I have been searching around, I found a lot of examples that compare two Lists. I have tried many of these examples but none of them end up with the right result.
For some reason it seems that the for loop skips the the first elements that are in the database List and only checks the last element. I am not sure if this is the only problem.
Here is a Snippet from my crafting system
//Crafting System C#
public void SearchIngredients()
{
int e = 0;
for(int i = 0; i < essentials.items.Count; i++)
{
ingredients[e] = essentials.items*.item.id;*
-
e++;*
-
}*
-
FindResultItem();*
-
}*
-
void FindResultItem()*
-
{*
-
int correct = 0;*
-
for(int i = 0; i < ItemBluePrintDatabase.bluePrints.Count; i++)*
-
{*
_ for(int k = 0; k < ItemBluePrintDatabase.bluePrints*.ingredients.Count; k++)_
_ {_
_ for(int c = 0; c < ingredients.Count; c++)_
_ {_
_ if(ItemBluePrintDatabase.bluePrints.ingredients[k] == ingredients*
```c_
*)
{
correct++;
break;
}
}
if(correct == ItemBluePrintDatabase.bluePrints*.ingredients.Count)
{
resultID = ItemBluePrintDatabase.bluePrints*.result;
break;
}
else
resultID = -1;
}
}
}
And here is my whole database script
//ItemBluePrintDatabase
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class ItemBluePrint
{
public List<int> ingredients = new List<int>();
public int result = -1;
public ItemBluePrint(List<int> ingredientItems, int resultItem)
{
ingredients = ingredientItems;
result = resultItem;
}
}
public class ItemBluePrintDatabase : MonoBehaviour
{
public static List<ItemBluePrint> bluePrints = new List<ItemBluePrint>();
void Start()
{
bluePrints.Add(new ItemBluePrint(new List<int>(new int[]{-1, 0, -1, -1, 0, -1, -1, 0, -1}), 2));
bluePrints.Add(new ItemBluePrint(new List<int>(new int[]{0, -1, -1, -1, -1, -1, -1, -1, -1}), 1));
bluePrints.Add(new ItemBluePrint(new List<int>(new int[]{0, 1, -1, -1, -1, -1, -1, -1, -1}), 2));
}
}
Thanks for the help in advance.
_```*_