Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Nov 01, 2008 8:27 pm   

ATCP prompt and %subregex
 
I'm sure I'm either misusing %subregex here or am writing it entirely wrong.

Either way...

Code:

 <pattern>Char\.Vitals</pattern>
    <value>$data=%subregex(%line,"H\:(\d+)\/(\d+)\sM\:(\d+)/(\d+)\sE\:\d+\/\d+\sW\:\d+\/\d+\sNL\:\d+\/\d+",\1|\2|\3|\4)
#show $data</value>


Gives

Code:

Char.Vitals
2848|2848|2536|2536


I know I could use #call %regex instead and capture predefines into variables, but I just started to play around with alternatives...

If I change $data to regular variable (string list), it also has "Char.Vials" as first item in the list.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Nov 01, 2008 9:21 pm   
 
Why bother with an embedded function? For starters, that's going to be much slower than using the same regex in the trigger pattern, because the pattern's compiled at runtime, every time. Just put that same regex into the trigger and use %1-%4 to store them somewhere.

Also, using a local variable for this means that the values won't be accessible outside that trigger, just fyi.

Oh, and if your question was about the Char.Vitals appearing, you should know that because telnet suboption text is zero-length, it can cause display problems if you use #show, #echo etc, same as if you tried to use #sub. If you want to display something, use an event to do it - you might find that's a good way to go about this anyway, just raise an event called CharVitals that has all the values as perameters, and then you can do whatever you like on that event after that.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Nov 01, 2008 10:10 pm   
 
I haven't played very much with ATCP yet so bare with me here.

Using the same regex individually would still make it a Telnet trigger or not?

About the Char.Vitals thing... I figured there might be something with #show etc but
once I changed local variable to regular one and let it capture 1-4 within %subregex,
it had Char.Vitals as first item. Afterwards came all the correct captures.

It just seemed weird for me, but as I said and you suggested, maybe I'm just
approaching all this incorrectly.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Nov 02, 2008 12:08 am   
 
Progonoi wrote:
Using the same regex individually would still make it a Telnet trigger or not?

Not sure what you mean.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sun Nov 02, 2008 12:35 am   
 
Well, what I meant to ask was that if the Regex within %regex(%line... construct would work on it's own with or without Telnet option checked.

Anyway, I already tried on my own and it does.

Thanks for the nudge towards right direction. Now my general Prompt trigger will make more sense and on the top of that likely be faster, too.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net