How do I grab all recipes available?

Applied the adjustments for testing and this is the outcome:image

CookingManager is a require function.

image
It definitely fixed the error but only provides 1 & 2 (which would be tomato & lavender from what I did previously)

local GameDataManager = require(game.ReplicatedStorage:WaitForChild("Modules").GameData)
local CookingManager = require(game.ReplicatedStorage:WaitForChild("Modules").CookingManager)


script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	for i, v in pairs(CookingManager:CheckMaterials(plr)) do
		for _, val in pairs(v) do
			print("Can Cook:" .. val)
		end
	end
end)

This will print the ingredients I believe.

If you have any other ideas on how I can do this checking for meals, then go ahead and suggest. It doesn’t have to be like I did.

This is the outcome of that:image (In my inventory where is only 1 Lavender, odd why it printed twice)

local GameDataManager = require(game.ReplicatedStorage:WaitForChild("Modules").GameData)
local CookingManager = require(game.ReplicatedStorage:WaitForChild("Modules").CookingManager)


script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	for i1, v in pairs(CookingManager:CheckMaterials(plr)) do
		for i2, val in pairs(v) do
			print("Can Cook:" .. i2)
		end
	end
end)

Let me know if this prints the indices.

It likely picked it up twice if it’s an ingredient for both recipes (that’s fine though).

image

function module:CheckMaterials(plr)
	local canCook = {}
	for i1, foodName in pairs(Recipes) do
		for i2, foodIngredient in pairs(foodName) do
			local backpack = plr.Backpack
			local char = plr.Character
			if backpack:FindFirstChild(foodIngredient) or char:FindFirstChild(foodIngredient) then
				if not table.find(canCook, i1) then
					table.insert(canCook, i1)
				end
			else
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
		end
	end
	print(#canCook)
	return canCook
end
local GameDataManager = require(game.ReplicatedStorage:WaitForChild("Modules").GameData)
local CookingManager = require(game.ReplicatedStorage:WaitForChild("Modules").CookingManager)


script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	for i, v in pairs(CookingManager:CheckMaterials(plr)) do
		print("Can Cook:" .. v)
	end
end)

INSANE PROGRESS!

Alright, so it works perfectly now BUT there is ONE issue.
I was checking since it actually gave me, and now if you only have 1 resource, it will mark as you being able to make the food

image

The red lines indicate specific stuff

First Section = Both tomato & lavender

Second section = Only tomato

Third section = Only Lavender (This is where the issue is. There is lavender in both meals)

function module:CheckMaterials(plr)
	local canCook = {}
	local ingredients = {}
	for i1, foodName in pairs(Recipes) do
		for i2, foodIngredient in pairs(foodName) do
			local backpack = plr.Backpack:GetChildren()
			local char = plr.Character:GetChildren()
			if backpack:FindFirstChild(foodIngredient) or char:FindFirstChild(foodIngredient) then
				table.insert(ingredients, foodIngredient)
				if not table.find(canCook, i1) then
					table.insert(canCook, i1)
				end
			else
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
			if #foodName ~= #ingredients then
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
		end
	end
	print(#canCook)
	return canCook
end
2 Likes

image
Screenshot by Lightshot < the script

function module:CheckMaterials(plr)
	local canCook = {}
	local ingredients = {}
	for i1, foodName in pairs(Recipes) do
		for i2, foodIngredient in pairs(foodName) do
			local backpack = plr.Backpack
			local char = plr.Character
			if backpack:FindFirstChild(foodIngredient) or char:FindFirstChild(foodIngredient) then
				table.insert(ingredients, foodIngredient)
				if not table.find(canCook, i1) then
					table.insert(canCook, i1)
				end
			else
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
			if #foodName ~= #ingredients then
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
		end
	end
	print(#canCook)
	return canCook
end

Excuse that, I added :GetChildren() to backpack and character because I was going to do something else but then ultimately changed my mind and forgot to remove them.

image

Section 1 = both
Section 2 = With tomato-, with lavender only.

image

It lacks the ability to get single ones as well now.

function module:CheckMaterials(plr)
	local canCook = {}
	local ingredients = {}
	for i1, foodName in pairs(Recipes) do
		for i2, foodIngredient in pairs(foodName) do
			local backpack = plr.Backpack
			local char = plr.Character
			if backpack:FindFirstChild(foodIngredient) or char:FindFirstChild(foodIngredient) then
				if not table.find(ingredients, foodIngredient) then
					table.insert(ingredients, foodIngredient)
				end
				if not table.find(canCook, i1) then
					table.insert(canCook, i1)
				end
			else
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
			if #foodName ~= #ingredients then
				if table.find(canCook, i1) then
					table.remove(canCook, table.find(canCook, i1))
				end
			end
		end
	end
	print(#canCook)
	return canCook
end

Meant to send this revision before, should be fine now.

1 Like

Had both tools, it yet again didn’t register the “Cooked Potato” and only focused on the “Fancy Dinner” which kinda sucks. image

All of these logs are me with both items in my backpack.

Still having this issue, annoyingly and haven’t really gotten anywhere with the ways i’ve attempted.

Try it with only lavender in it. It seems it looks for the first available recipe that it can create. You can avoid this by alllowing the player to choose the recipe they make.

1 Like