[help] Trigger / Regex on Directions

Post Reply
icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

[help] Trigger / Regex on Directions

Post by icesteruk »

I'm trying to capture

You see exits leading north (open pine door), northeast (open pine door), east, southeast (open pine
door), south (open pine door), southwest, west (open pine door), northwest, and in.

And other direction triggers but I don't want the (open pine door), (closed pine door) etc.. and sometimes its not pine but wood doors.. And for it to be placed without a stinglist.

So far I have
Code: [show] | [select all] lua
^You see exits leading (.+).$
Code: [show] | [select all] lua
local gdir = matches[2]:gsub("and ", "")

local gdir_table = string.split(gdir, ", ")
display(gdir_table)
which shows

{
"north (open pine door)",
"northeast (open pine door)",
"east",
"southeast (open pine door)",
"south (open pine door)",
"southwest",
"west (open pine door)",
"northwest",
"in"
}

Any help with be greatful!

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: [help] Trigger / Regex on Directions

Post by Akaya »

Since there are only a set amount of directions, you could store them in one table, check them against your string, and add them to another table.
Code: [show] | [select all] lua
local dirs = {"north","south","east","west","northeast","northwest","southeast","southwest","in","out","up","down"}
local my_string = string.split(matches[2]," ")
local gdir_table = {}
for k,v in pairs(dirs) do
  if table.contains(my_string, v) then
    table.insert(gdir_table, v)
  end
end
display(gdir_table)

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: [help] Trigger / Regex on Directions

Post by icesteruk »

Its not even classing the door as a exit/entrance now.. This is what I get

You see exits leading north (open pine door), northeast (open pine door), east, southeast (open pine
door), south (open pine door), southwest, west (open pine door), northwest, and in.

{
"east",
"northwest",
"southwest"
}

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: [help] Trigger / Regex on Directions

Post by demonnic »

Code: [show] | [select all] lua
myString="north (open pine door)"
myString=myString:gsub("%s+(.*)", "")
print(myString)
quick bit of code to demonstrate stripping the (open pine door) portion of the direction. You can run it over at http://www.lua.org/cgi-bin/demo

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: [help] Trigger / Regex on Directions

Post by Akaya »

Just ran my code against that string and worked just fine.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: [help] Trigger / Regex on Directions

Post by icesteruk »

Akaya wrote:Just ran my code against that string and worked just fine.

Not to sound ungreatful but I ran the code you put and, it didnt show the exits with doors heh .. But, That might work for what im after :)

Thank you

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: [help] Trigger / Regex on Directions

Post by Akaya »

Sorry. Should've posted just the idea. Not the code.

Post Reply