Finding value in tables problem

Post Reply
azure_glass
Posts: 97
Joined: Wed Jul 25, 2012 12:35 pm

Finding value in tables problem

Post by azure_glass »

Hi :)

I have litle problem with tables
i can do it by "elseif' but it will be more than 100 "elseifs" :/

if matches[3] == "meat" then
xsxsxs = "banana"
echo("" .. xyz .. "" .. xxyz .. "" .. xsxsxs .. "]")

happyJaneTable = { "meat", "burger", "steak", "hamburger", "chickenburger" }
sadisJaneTable = { "banana", "apple", "orange", "pear", "grape" }
moddyJaneTable = { "xxx", "yyy", "ccc", "bbb", "aaa" }
You see meat.
send("eat banana")

You see burger.
send("eat apple")

You see Burger.
send("eat apple")

You see meat.
send("eat xxx")

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Finding value in tables problem

Post by Delrayne »

So...you are going to have to explain a bit more on what you want to be doing exactly. Just by the looks of it though, you might want to try changing your table.
Code: [show] | [select all] lua
janeTable = {
    ["meat"] = {
        ["sadis"] = "banana", 
        ["moddy"] = "xxx",
    }, 
    ["burger"] = {
        ["sadis"] = "apple",
        ["moddy"] = "yyy",
    },
    etc.....
}
And like wise you can check through them like so.
Code: [show] | [select all] lua
for k, v in pairs (janeTable) do
--Check to see if matches[2] is in janeTable, and if someVariable is set to sadis or moddy
    if (k == matches[2] and someVariable == "sadis") then
        send("eat " .. janeTable[k].sadis)
        break
    elseif (k == matches[2] and someVariable == "moddy") then
        send("eat " .. janeTable[k].moddy)
        break
    end
end

azure_glass
Posts: 97
Joined: Wed Jul 25, 2012 12:35 pm

Re: Finding value in tables problem

Post by azure_glass »

Thak you :)

Post Reply