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 5 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]

01local sl1 = script.Parent.Slot1.Item
02local sl2 = script.Parent.Slot2.Item
03local sl3 = script.Parent.Slot3.Item
04local sl4 = script.Parent.Slot4.Item
05local result = script.Parent.ResultImage
06local ingreds = {
07    "Sticks",
08    'Logs',
09    'Rocks',
10 
11}
12 
13while wait() do
14    --CraftingTable
15    if sl1.Value == ingreds[1] and sl2.Value == ingreds[1] and sl3.Value == ingreds[1] and sl4.Value == ingreds[1] then
View all 22 lines...
0
u could make the slots in a table also? IcyMizu 122 — 5y

1 answer

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

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

01local slots = {script.Parent.Slot1.Item.Value,script.Parent.Slot2.Item.Value,script.Parent.Slot3.Item.Value,script.Parent.Slot4.Item.Value}
02local recipes = {
03 ["campfire"] = {"sticks","sticks","sticks","sticks"};
04 ["baseball bat"] = {"rocks","logs","logs"};
05}
06 
07for thingThatWillBeCrafted, ingredients in pairs(recipes) do
08 for i = 1, #ingredients do
09  if slots[i] == ingredients[i] then
10   done[i] == true
11  end
12 end
13 if #done == #ingredients then
14  print("crafted ".. thingThatWillBeCrafted)
15 else
16  print("nothing")
17 end
18end
0
Didn't work unfortunately. I'll give you an update if I somehow altered it to make it work AntoninFearless 622 — 5y
Ad

Answer this question