Skip to main content
Describe the help you need in the title
Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Need help with a How to determine whether multiple crafting systemrequirements are met?

fixed typos & grammar errors, tweaked layout/formatting (OP had lots of single line breaks that got ignored - changed those to a list)
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

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! :)

I'm currently working on a crafting system - this systems works fine when the disired item has only one requirement. If there is more then one requirement the system is broke.

Short description of how the system (should 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. The right output is my problem!

// 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 mistake? Do I pursue the right approach?

I appreciate all of your help! :)

I'm currently working on a crafting system - this systems works fine when the desired item has only one requirement. If there is more then one requirement the system brakes.

Here's a short description of how the system should work:

  • 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 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? Is there something wrong with my approach?

Source Link

Need help with a crafting system

I'm currently working on a crafting system - this systems works fine when the disired item has only one requirement. If there is more then one requirement the system is broke.

Short description of how the system (should 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. The right output is my problem!

Item Class:

[System.Serializable] public class Item { public ScripableTradegood scripableTradegood; public int amount; } 

Warehouse:

[Header("Warehouse Content")] public List<Item> warehouseContent; 

Scriptable Object:

[Header("Requirements")] public List<Item> tradegoodRequirements; 

Here the problem:

// 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 mistake? Do I pursue the right approach?

I appreciate all of your help! :)