How would i be able to check for a recipe inside a table

Hello, i have a question how would i be able to check a value inside a table made out of tables? for example when a resource is grabbed by the refinery it finds the recipe whit the required values then makes the object

ive searched on the the devorum and couldnt find anything that could suit my case
example table:

local module = {
	
	RefinerRecipes = {
		
		RefinedIron = {
			
			IronOre = 1;
			output = "RefinedIron";
			
		}
		
	}
	
}

return module

Currently looks like you have this as a module script, may be good to review their docs
So something like

local recipes = require(insertPathToYourModuleScriptHere)

recipes.RefinerRecipes.RefinedIron.output
2 Likes

Mine is still early development so I’m still tweaking it and what not but this is sort of how I have mine setup

So I only have two items so far but basically how I’ve got it structured is I have the actual item itself then the recipe to make it and if the recipe is empty then it’s possibly an item made out of an extractor or one that just gets spawned in, for stuff like my Planks I have that as what item it requires and then the quantity of it.

So example every 1 Wood is 2 Planks and that takes 2 seconds to create which would get you 60 Planks per minute.

Here’s my math for calculating output per minute

quantity * 60 / duration = IPM

return {
	["Wood"] = {
		Section = "Extractor";
		itemName = "Wood";
		itemImage = "rbxassetid://127419372826994";
		Receipe = {};
		
		Duration = 1,
		Output = 1
	};
	
	["Planks"] = {
		Section = "Standard Parts";
		itemName = "Planks";
		itemImage = "rbxassetid://71306535518403";
		Receipe = {
			["Wood"] = 1
		};
		
		Duration = 2,
		Output = 2
	}
}

Now this code is extremely work in progress so don’t judge it to hard but is functional (at least in my setup) you will need to create your own but it’ll at least give you an idea at least

local outputProduction = getProductionDetails(belt)
local productionMet = {}

for _, itemDetails in outputProduction.Input do
	productionMet[itemDetails.itemName] = if quanityInTable(belt:getOverflow(`{itemDetails.itemName}-input`)) >= itemDetails.Output then true else nil
end

local canProduceItem = quanityInTable(productionMet) == quanityInTable(outputProduction.Input)

--// Remove items from input-overflow
if not canProduceItem then return end

for _, item in outputProduction.Input do
	-- removeItems needed
	for i = 1, item.Output do
		local firstItem = belt.Overflow[`{item.itemName}-input`][1]
		belt:removeOverflow(`{item.Name}-input`, firstItem)
		-- Destroy Item!
	end
end

for _, item in outputProduction.Output do
	for i = 1, item.Output do
		local createItem = ClassService.Item.new(item.itemName)
		belt:addOverflow("output", createItem, overflowQuanity)
	end
end

warn("Start Item Craft")

For reference this is the information that outputProduction is using

{
	Details = {
		Duration = currentConstructingData.Duration;
		itemName = currentConstructingData.itemName;
		itemImage = currentConstructingData.itemImage;
	};
	Input = InputItems;
	Output = {
		{ -- Item Data
			itemName = currentConstructingData.itemName,
			itemImage = currentConstructingData.itemImage,
			Output = currentConstructingData.Output,
			PerMinute = (currentConstructingData.Output * 60) / currentConstructingData.Duration
		}	
	};
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.