Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

items from 1st table goes inside of the table before?

Asked by 2 years ago

I'm trying to make a recipe system that detects which recipe your doing by looking at a bunch of tables, but somehow 1 of the recipes items are going into the table before. Took a while to wrap my head around it.

local recipes = {["Soba"] = {["Bowl"] = 0, ["Soba Noodles"] = 0, ["Soba Broth"] = 0}, ["Tempura Udon"] = {["Bowl"] = 0, ["Udon Noodles"] = 0, ["Udon Broth"] = 0, ["Tempura"] = 0}}

local currentRecipe = {["Bowl"] = 0, ["Soba Noodles"] = 0,["Udon Noodles"] = 0, ["Soba Broth"] = 0,["Udon Broth"] = 0, ["Tempura"] = 0}

local oldCurrentRecipe = currentRecipe
local oldRecipes = recipes

local renameAdvanced = {}

local function readRecipe()
    for i,w in pairs(recipes) do
        local ones = 0
        local length = 0
        for k,v in pairs(currentRecipe) do
            if v == 1 then
                w[k] = 1
            end
        end
        for s,key in pairs(w) do
            if key == 1 then
                ones = ones + 1
            end
            length = length + 1
            print(i, s)
        end
        print(ones, length)
        if ones == length then
            print("recipe detected is " .. i)
            return tostring(i)
        end
    end
    return "Unknown"
end

Output: Image first value is the table/recipe it's supposed to be in

Answer this question