Tables and Matching a Line

Posted by Slick2175 on Fri 06 Jan 2012 07:03 PM — 7 posts, 27,522 views.

USA #0
What Im looking for is when the trigger fires, I want it to Send Look and check to see if a line pops up that matches whats stored inside a table.

So like

v = {
"You see a orc.",
"You see a cow",
}

Send("look")

If line matches v
then
Send("It works")
else
Send("No good")

end

Its been forever since ive done any scripting, Im thinking the tables need to be accessed and expanded for one, then using wait.match to wait for the line? I just dont know how to access the table and see if it matches a line.
Australia Forum Administrator #1
You could use the wait module, although you could achieve much the same effect with a trigger that you enable after doing a "look".

Anyway, for a table like that, you would just iterate through it, see if what you got was in it:


for k, v in ipairs (mytable) do
  if input_line == v then 
    Send ("matched")
  end -- if
end -- for


Or if you did the table a different way you could do a keyed lookup.
USA #2
THANK YOU.

for k, v in ipairs (mytable) do

thats what I couldnt remember. much appreciated :)
USA #3
Ok i got this so far


require "wait"
mytable = {
"A cityguard stands here.",
"|@ Richard is standing here.",
}
wait.make (function ()
for k, v in ipairs (mytable) do
Send("look")
if line_input == wait.match (v, 3)
then
Send("theresomethinghere")
else
Send("nothingshere")
end -- if
end -- for
end) -- wait



It triggering theresomethinghere twice when there is nothing in the room that matches mytable.


If there is something in the room that matches I get the theresomethinghere and a few seconds later it shoots off nothingshere

I cant find anything for line_input so im assuming its not a function.


What Im trying to do is after i kill a mob I need it to

Send("look")
and make sure there are no other monsters in the room that match mytable. If there is I need it to enable the kill trigger group, if there isint then I need it to resume speedwalk.

So after it finds a line of text that matches mytable I need the for to stop running through the list.

Amended on Sun 08 Jan 2012 04:00 AM by Slick2175
USA #4
So looking around looks like I might need to use string.find and string.match?

but im lost on how to do it.
Australia Forum Administrator #5

if line_input == wait.match (v, 3)


Check out this stuff about the wait module:

http://www.gammon.com.au/forum/?id=4957

Your number 3 does not appear to me to be a useful thing to be matching on.
Australia Forum Administrator #6
http://www.gammon.com.au/scripts/doc.php?lua=string.find