I am in a situation where I am checking if a certain object contains certain components and does NOT contain other components.
To put it concretely, let's make ice cream.
There are 3 orders. Vanilla Sprinkles Gummies
"Sprinkles" and "Gummies" must have "Vanilla" as a component as well.
-- All their orders will be represented in strings
-- The problem I have is, how can I detect if the ice cream has vanilla and not the other ingredients? Also, how can I detect if the ice cream has vanilla and whatever was ordered as the topping? This is my if statement.
-- My main goal is to solve this problem on a scalable level, so if i add more ingredients I don't have to complicate my logic even further. I need help with constructing a sort of algorithm.
local ingredients = {"Vanilla", "Sprinkles", "Gummies"}
local iceCreamObj = obj -- doesn't matter. Just say it is a table
-- :Has() function is for simplicity.
local order = "Gummies"
function check()
if iceCreamObj:Has(order) and iceCreamObj:Has("Vanilla") then
return true
end
return false
end
check() -- true
-- See, this looks innocent, right? There is something missing here. What the ice cream has the order "Gummies" as well as "Sprinkles"? The if statement wouldn't detect that the sprinkles were there. How can I solve this? Should I make a table of ingredients excluding the vanilla and the ordered topping and loop through the ice cream's components to see if anything extra was added?
