Register forum user name Search FAQ

Gammon Forum

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 ➜ string.match("You eat orphine.", "You eat (orphine|violet).")

string.match("You eat orphine.", "You eat (orphine|violet).")

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #15 on Thu 01 Jul 2010 03:47 AM (UTC)

Amended on Thu 01 Jul 2010 03:48 AM (UTC) by Twisol

Message
Trevize said:

Am I a retard again or not making my point clear :(

trigger_add("^You (\d+) Points\.$", nil, nil, "Replaced")

function trigger_add(pattern, send, script, replace)
table.insert(tTriggers, { pattern = pattern, send = send, script = script, replace = replace })
end

This is how I add my "so called" triggers into the table that checks against the mud's output. The problem I'm having is that the string that's in tTriggers table now does'nt match because it's like this: ^You (d+) Points.$

You showed me that I could use [[ ]] to fix that problem, but it seems to me that the only way to add a long string like that with my function is to supply it in the "call" to the function, like:
trigger_add([[^You (\d+) Points\.$]], nil, nil, "Replaced")

And I was hoping that I would'nt have to do that because (to me) it looks more ugly and possible harder for anyone else using this function to understand. I had hopes that I could do something like I have, and just make the insert do this: table.insert(tTriggers, { pattern = [[pattern]], send = send, script = script, replace = replace }) or something similiar..

Anyway I'm starting to think that it's either that or double "\" to escape the second backslash..

Thanks for your time and patience with me and this thread. It's much appreciated!



Use this.

trigger_add("^You (\\d+) Points\\.$", nil, nil, "Replaced")


Or this.

trigger_add([[^You (\d+) Points\.$]], nil, nil, "Replaced")



It's really the only way. This is something you have to deal with at the syntactic level. Once the string is parsed, there's no going back to fiddle with the escapes.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Trevize   (21 posts)  Bio
Date Reply #16 on Thu 01 Jul 2010 04:04 AM (UTC)
Message
Thanks alot, it answers all my questions..

Pretty much what I suspected but I had small hopes that there was some way to add like a variable into the long strings, although thinking about it, it would'nt have worked either since the string is already parsed and the \ is removed.. Oh well, I'll deal with it.

Thanks once again for all the help.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #17 on Thu 01 Jul 2010 04:13 AM (UTC)
Message
Trevize said:
the string is already parsed and the \ is removed.

Yep, that's exactly the problem. =/

Trevize said:
Thanks once again for all the help.

Sure.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

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.


66,969 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.