I'm currently working on a crafting system - this systems works fine when the disireddesired item has only one requirement. If there is more then one requirement the system is brokebrakes.
ShortHere's a short description of how the system (shouldshould work) works before talking about code.:
- Every object has a monobehaviour-script which holds an scriptable object.
- This scriptable object contains all the statistics and has a list of required items.
- The warehouse has a monobehaviour-script and this has a list of content items.
- To craft a new item it should compare the content with the requirements.
- Based on the output the object will spawn.
Every object has a monobehaviour-script which holds an scriptable object. This scriptable object contains all the statistics and has a list of required items. The warehouse has a monobehaviour-script and this has a list of content items. To craft a new item it should compare the content with the requirements. Based on the output the object will spawn. The right output is my problem! is getting the right output.
// Loop through the requirements foreach (Item requirement in tradegoodRequirements) { // For each requirement check content in warehouse foreach (Item content in warehouse.warehouseContent) { // When content is not requirement skip the check if (content.scripableTradegood != requirement.scripableTradegood) continue; // When right content was found if (content.scripableTradegood == requirement.scripableTradegood) { // If required content amount isnt present return if (content.amount < requirement.amount) return; /* * When the tradegood has only one requirement - I could just substract the requirements and exit out of the function. * But when if I have more then one requirement - how can I check if all requirements a present before substracting them? * Logically I would have to leave the second loop and continue to check the requirements from the first loop - But how can I achieve that? * */ } } } Where is my mistake? Do I pursue the rightIs there something wrong with my approach?
I appreciate all of your help! :)