Not at all what I need it to do. MyTable2 could be a random check. It might not necessarily be “Bruh”. So thats why I need to find it. Im trying to do this basically
local MyTable = {"A", "B", "C"}
print(MyTable["A"])
But the MyTable2 changes. Don’t really know any other way to explain it.
you need to use a for in pair loop to compare the tables
local MyTable = {Bruh = 100}
local MyTable2 = {Bruh = 10}
local Table1Bruh = 0
local Table2Bruh = 0
print("You have:")
for itemName, itemValue in pairs(MyTable) do
if itemName == "Bruh" then
Table1Bruh = itemValue
end
end
for itemName, itemValue in pairs(MyTable2) do
if itemName == "Bruh" then
Table2Bruh = itemValue
end
end
print(Table1Bruh)
print(Table2Bruh)
Just realized you have a sub table. This code will only work on a regular table…
local Table = {Value1 = {Sweets = 10}, Value2 = {Chocolate = 1}, Value3 = {Lolipops = 10}}
local function GetItem(item)
for _, v in Table do
if Item.Requirements == v then
print ("Found")
-- Here I then want to compare the 2 numbers to see if they are equal
end
end
end)
GetItem({Requirements = {Chocolate = 10}})
It might not be chocolate every time. It might be sweets, or lollipops. But it could be random, that’s why I need to index it.
local Table = {{"Sweets", 15}, {"Chocolate", 10}, {"Lolipop", 10}}
local function GetItem(item)
for _, v in pairs(Table) do
for _, vx in pairs(item.Requirements) do
if vx[1] == v[1] then
if vx[2] == v[2] then
print("Found!", v[1])
end
end
end
end
end
GetItem({Requirements = {{"Sweets", 15}, {"Chocolate", 10}}})
I think that should work, tried looking some things up.
If not I don’t know what the problem may be.
local Table = {
["Sweets"] = 10,
["Chocolate"] = 10,
["Lolipops"] = 10
}
local function GetItem(item)
for namex, v in pairs(Table) do
for name, itemRequirement in pairs(item.Requirements) do
if name == namex then
if v >= itemRequirement then
print("Found!", name, itemRequirement)
end
end
end
end
end
GetItem({Requirements = {
["Chocolate"] = 11,
["Sweets"] = 10
}})
local Table = {Value1 = {Sweets = 10}, Value2 = {Chocolate = 1}, Value3 = {Lolipops = 10}}
local function GetItem(item)
for req_name, req_value in pairs(item.Requirements) do
for _,v in pairs(Table) do
if v[req_name] then
print ("Found")
if v[req_name]==req_value then print("numbers are equal")
else print ("numbers are NOT equal") end
break
end
end
end
end
GetItem({Requirements = {Chocolate = 10}})