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

Is there an easier way to make crafting recipes?

Asked by 4 years ago

Hello, I am making a survival game and it has a crafting table. I found a way to make it function but I believe there could be an easier way, let's say I could make recipes within an array. Is this possible?

Current code [LocalScript]

local sl1 = script.Parent.Slot1.Item
local sl2 = script.Parent.Slot2.Item
local sl3 = script.Parent.Slot3.Item
local sl4 = script.Parent.Slot4.Item
local result = script.Parent.ResultImage
local ingreds = {
    "Sticks",
    'Logs',
    'Rocks',

}

while wait() do
    --CraftingTable
    if sl1.Value == ingreds[1] and sl2.Value == ingreds[1] and sl3.Value == ingreds[1] and sl4.Value == ingreds[1] then
        result.Image = 'http://www.roblox.com/asset/?id=151913757'

    else
        result.Image = ''
    end
    ------
end
0
u could make the slots in a table also? IcyMizu 122 — 4y

1 answer

Log in to vote
0
Answered by
zeptak 4
4 years ago

Not sure if this is gonna work... but it could be made like that

local slots = {script.Parent.Slot1.Item.Value,script.Parent.Slot2.Item.Value,script.Parent.Slot3.Item.Value,script.Parent.Slot4.Item.Value}
local recipes = {
 ["campfire"] = {"sticks","sticks","sticks","sticks"};
 ["baseball bat"] = {"rocks","logs","logs"};
}

for thingThatWillBeCrafted, ingredients in pairs(recipes) do
 for i = 1, #ingredients do
  if slots[i] == ingredients[i] then
   done[i] == true
  end
 end
 if #done == #ingredients then
  print("crafted ".. thingThatWillBeCrafted)
 else
  print("nothing")
 end
end
0
Didn't work unfortunately. I'll give you an update if I somehow altered it to make it work AntoninFearless 622 — 4y
Ad

Answer this question