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
➜ General
➜ A complicated regex Trigger
A complicated regex Trigger
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2 3
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #15 on Sun 05 Mar 2006 03:48 AM (UTC) |
Message
| As you can see, Achaea preparses the description into a big paragraph, that's why I can't assume there's an end line at the end of a sentence, and I must assume any space can be replaced with a newline. | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #16 on Mon 13 Mar 2006 03:49 AM (UTC) |
Message
| Although I haven't 100% checked this, I think to be accurate that Achaea does not replace spaces with newlines, but inserts newlines after spaces when its wrapping. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #17 on Mon 13 Mar 2006 04:56 AM (UTC) |
Message
| It seems safe to assume that Achaea is trying fairly hard to make it difficult to parse their output with simple triggers.
The only suggestion I can make is this:
- Somehow detect the ends of the description (start and finish)
- As it arrives, build it up into a big block of text
- Once you have the whole description, replace newlines with a space
- Convert multiple spaces to one space
- Break up the resulting block of text into sentences (ie. ending with periods)
- Apply a regexp to each sentence to see if it matches what you want.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #18 on Mon 13 Mar 2006 09:48 PM (UTC) |
Message
| Yeah, Im going to use UDP to send it to a C++ program and have it parse it into sentences. Then start splitting the sentences to pieces one at a time. Im worried about the speed penalties of doing this though. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #19 on Mon 13 Mar 2006 09:55 PM (UTC) |
Message
| I wouldn't worry about the speed consequences of this. All you're doing is moving some bytes to a running program, which will split into sentences. All of this is quite cheap, computationally.
I'm curious though why you're sending this to an external program, and why you chose UDP. Why not just have a running Lua script that takes care of this for you? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #20 on Tue 14 Mar 2006 05:23 AM (UTC) |
Message
| C++ classes, OOP design for my combat system. Also, GUI components that I can't create inside of MUSHClient. And it's faster for processing complex tasks. I chose UDP because I know nothing about COM objects and UDP was the only other method that people have mentioned to send data to a third (second?) program. I also could have written DLLs for Lua in C but frankly I felt this was also unnecessary considering I could just use a full blown executable with gauges, buttons, and the works.
Also, less logical, but I know C++ is fast and I feel more comfortable writing complex and computationally expensive functions in it than I would in any scripting language. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #21 on Tue 14 Mar 2006 05:29 AM (UTC) |
Message
| Oh, I didn't know you were doing all that other stuff. In that case it makes sense to have C++, especially if you've already written all this other code for it.
I was surprised to hear you say UDP, and not just plain old normal TCP sockets, examples of which abound for Winsock. UDP seems to be a slightly more unusual route to me.
FWIW, Lua is an extremely fast scripting language. It is more than sufficient for any kind of processing people would be doing for a MUD. People can render 640x480 images at hundreds of frames per second with Lua doing the grunt-work; surely that is sufficiently fast for a measly little text parser? :-)
(Don't forget that text parsing is really a very inexpensive task in general. If you don't believe me, write some perl scripts that chunk over megabytes of data and do something (un)interesting. You might be surprised by the speed results.) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #22 on Tue 14 Mar 2006 09:42 PM (UTC) Amended on Tue 14 Mar 2006 09:44 PM (UTC) by Nexes
|
Message
| I use UDP because of the MUSHClient supplied functions for sending and receiving UDP packets. Otherwise, I have no idea how I would establish a connection between MUSHClient and my program. :(
And I distrust string operations because of my experience in Java. It was...incredibly slow with the strings. Concatenating, and everything else really ate up my memory and while I found the string buffers in Lua to be exceedingly simple to use I have since distrusted string operations. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #23 on Tue 14 Mar 2006 09:51 PM (UTC) |
Message
| Do you mean Java or Javascript? I've not had problems you describe using strings in Java. There are some gotchas, especially if you're building very large strings a few characters at a time, in which case you actually want to use a StringBuffer (or StringBuilder in 1.5 I think it's called). That way, you allocate a chunk of memory once, and then fill it up. But, this also applies to C++ strings.
But again, I'd be quite surprised if you had problems with strings in Java. I wrote a program for work that takes several hundred session logs, reads them all in, does black magic on them involving very many string operations per session, and the blocking part is disk access, not string manipulation. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #24 on Wed 15 Mar 2006 12:11 AM (UTC) |
Message
| I meant Java. I dunno, maybe my virtual machine sucked :( | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #25 on Wed 15 Mar 2006 05:48 AM (UTC) |
Message
|
Quote:
Yeah, Im going to use UDP to send it to a C++ program and have it parse it into sentences
Personally I wouldn't use UDP in this application. A UDP packet is limited in size (something around 512 bytes) so a long description would need to be split between packets, reassembled at the receiving end, and so on.
If you look at this forum post:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6034
... I did 200,000 string.find operations (that is, the Lua regexp) in one second, so I don't think speed will be an issue. Also, I recently wrote an application in Lua that read in all my old email messages, parsed the headers, and added them to an SQL database. The whole thing ran really fast, processing something like 5,000 emails in a minute or so. There was no problem with string management. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #26 on Wed 15 Mar 2006 04:30 PM (UTC) |
Message
| Might I suggest a way to make this easier? (wouldn't want to take away from your project though Nexes, hehe)
CONFIG SCREENWIDTH 250
and set MushClient to do your wrapping for you... It won't be perfect, since descriptions are often longer than 250 characters, but it might make things a bit easier. | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #27 on Thu 16 Mar 2006 12:25 AM (UTC) |
Message
| My screen width is already set at 240.
Hmm, I guess I would have to figure out the max length of a UDP packet, and figure out how many charachters that translates into. If it's above 240 then it shouldn't be a problem, otherwise maybe your method would be better Nick. | Top |
|
Posted by
| Rakon
USA (123 posts) Bio
|
Date
| Reply #28 on Mon 01 May 2006 07:32 PM (UTC) |
Message
| Well now. Achaea now allows you to CONFIG SCREENWIDTH 0, so try that if you'd like. However I'd think it'd be much simpler to target a person IE 'set summoner Yuna/<person>', and have a trigger match on the line that the name is in. In Cyan or whatever you use for a 'player' color. Thus, when the trigger matched you could make the REGEX '(She|he) is wielding (a|an) (.*?) in (his|her) (right|left) hand
.' I don't know how you'd account for a newline in the description however, maybe use the REGEX to do a few ( |\n) ??
Good Luck
--Rakon |
Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for. | Top |
|
Posted by
| Nexes
(65 posts) Bio
|
Date
| Reply #29 on Fri 05 May 2006 03:06 AM (UTC) |
Message
| I read about the screenwidth 0 thing the moment the put it in and I love it.
Actually that brings Nick's point even more relevant since I definitely will run into that limit on packet size now, at least if I send it all in one packet.
Anyways, the reason I don't want to do it your way, Rakon, is because that's not quite what I wanted to do. The trigger pattern you mentioned is exactly what I wanted to avoid, since it fires multiple times if it comes in less lines than I set the trigger to capture. Also I don't want to limit the capture to only my target. | 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.
92,148 views.
This is page 2, subject is 3 pages long:
1
2 3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top