Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Tables and Matching a Line
|
Tables and Matching a Line
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Slick2175
USA (27 posts) Bio
|
| Date
| Fri 06 Jan 2012 07:03 PM (UTC) |
| Message
| 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. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Fri 06 Jan 2012 07:13 PM (UTC) |
| Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Slick2175
USA (27 posts) Bio
|
| Date
| Reply #2 on Fri 06 Jan 2012 07:18 PM (UTC) |
| Message
| THANK YOU.
for k, v in ipairs (mytable) do
thats what I couldnt remember. much appreciated :) | | Top |
|
| Posted by
| Slick2175
USA (27 posts) Bio
|
| Date
| Reply #3 on Sun 08 Jan 2012 03:42 AM (UTC) Amended on Sun 08 Jan 2012 04:00 AM (UTC) by Slick2175
|
| Message
| 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.
| | Top |
|
| Posted by
| Slick2175
USA (27 posts) Bio
|
| Date
| Reply #4 on Sun 08 Jan 2012 04:25 AM (UTC) |
| Message
| So looking around looks like I might need to use string.find and string.match?
but im lost on how to do it. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Mon 09 Jan 2012 05:59 AM (UTC) |
| Message
|
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Mon 09 Jan 2012 06:00 AM (UTC) |
| Message
| |
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
25,861 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top