Matching a word from a lua table string

Posted by Strazor on Mon 01 Sep 2014 09:53 PM — 3 posts, 15,792 views.

USA #0
In a previous post here: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=12569 Nick showed me how to sort my table by adding keys or extract information. What I am trying to do now is match a particular word from a string of words in a table. Here is my current table.


equipinform = {

["468263929"] = {
    level=1,
    weight=1,
    wearloc="sleeping",
    details_captured=true,
    stats = {},
    owner="Strazor",
    objectid="12569898",
    flags="glow, hum, magic, held, nopurge, burn-proof, nolocate, solidified, resonated, illuminated, v3, precious",
    itemtype="Furniture",
    container_id="worn",
    resists = {},
    name="V3 Trivia Sleeping Bag",
    score="0",
    },

["965742031"] = {
    level=41,
    weight=0,
    wearloc="neck",
    details_captured=true,
    stats = {
      damageroll=29,
      luck=2,
      moves=-30,
      wisdom=2,
      intelligence=2,
      hitroll=1,
      hitpoints=25,
      },
    owner="",
    objectid="125689755",
    flags="unique, glow, hum, magic, held, burn-proof, solidified, illuminated, v3, searchable",
    itemtype="Armor",
    container_id="worn",
    resists = {},
    name="(>Asura's Azurite Pearl<)",
    score="205",
    }

} -- end of equipinform

tprint (equipinform)


Looking at the above table "flags" contains a lot of information. I would like to match the word "precious" so the script prints only the item(s) that have this keyword. For now a simple, true/false would work. Does lua provide a statement that allows this sort of data matching?
USA #1
Well, as most things go. Ask a question and the answer usually presents itself.

I realized that I can set a variable to match the string I would like.


var = item.flags

if string.find (flagtype, "precious") then
     ColourNote ("red", "black", "FLAG FOUND")
else
     ColourNote ("red", "black", "FLAG NOT FOUND")
end

print(item.flags)  -- verify if statement works correctly


edit -- changed the above code to fix the error Nick discusses below with print().
Amended on Tue 02 Sep 2014 09:25 AM by Strazor
Australia Forum Administrator #2

print("item.flags")  -- verify if statement works correctly


Should be:


print(item.flags)  -- verify if statement works correctly


... shouldn't it?

But yes, doing a string.find or a string.match should let you search for a particular flag.