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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Tygerhart
Novice


Joined: 04 Oct 2001
Posts: 43
Location: Canada

PostPosted: Sat Feb 07, 2004 12:13 pm   

Translation alias dilemna
 
Just when I think I got it figured out, a new and inexplicable problem rears it's ugly head. Very Happy

I've been able to get that translation alias working on all my IC channels (Tip of the hat and a big thanks to Rorso and Nexela Smile), but I'm having problems with a person to person channel. Here's what I mean...

How the raw, unaliased command is typed
p2p peter=I'm making a card.

How I type the aliased command
p2p peter I'm making a card.

What I'm trying to achieve
p2p peter=I'mmmm mmmmaking a carrrrd. Mmmmm?

What I'm actually getting
p2p peter=peterrrr I'mmmm mmmmaking a carrrrd. Mmmmm? I'm making a card.


Here's the alias that I've got

ALIAS
p2p

VALUE
~p2p %1=%subregex( %0, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?


Any idea what I'm doing wrong there?

Once again, any and all help will be greatly appreciated. Smile

Thanks,
Tygerhart
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sat Feb 07, 2004 12:41 pm   
 
quote:
Originally posted by Tygerhart

Just when I think I got it figured out, a new and inexplicable problem rears it's ugly head. Very Happy

I've been able to get that translation alias working on all my IC channels (Tip of the hat and a big thanks to Rorso and Nexela Smile), but I'm having problems with a person to person channel. Here's what I mean...

How the raw, unaliased command is typed
p2p peter=I'm making a card.

How I type the aliased command
p2p peter I'm making a card.

What I'm trying to achieve
p2p peter=I'mmmm mmmmaking a carrrrd. Mmmmm?

What I'm actually getting
p2p peter=peterrrr I'mmmm mmmmaking a carrrrd. Mmmmm? I'm making a card.


Here's the alias that I've got

ALIAS
p2p

VALUE
~p2p %1=%subregex( %0, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?


The problem is the first %0 which copies the entire argument list of the alias into the translation. Here is how to solve it:
The new p2p alias:
#exec %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

How does this work? Well the first step is that we attempt to match the argument with the regular expression. It will copy the name of the target character to the variable p2pName. Then it'll copy the message to the p2pMessage variable. We then send the message to the translation function.

Good luck Smile
Reply with quote
Tygerhart
Novice


Joined: 04 Oct 2001
Posts: 43
Location: Canada

PostPosted: Sat Feb 07, 2004 1:00 pm   
 
quote:
Originally posted by Rorso
The problem is the first %0 which copies the entire argument list of the alias into the translation. Here is how to solve it:
The new p2p alias:
#exec %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

How does this work? Well the first step is that we attempt to match the argument with the regular expression. It will copy the name of the target character to the variable p2pName. Then it'll copy the message to the p2pMessage variable. We then send the message to the translation function.

Good luck Smile



Ok. I must be doing something wrong... Here's what I've got now...


ALIAS
p2p

Value
#exec %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

I'm getting this returned to the MU*
0
p2p = Mmmmm?


Any idea why it's not working?

Thanks,
Tygerhart
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sat Feb 07, 2004 1:12 pm   
 
quote:
Originally posted by Tygerhart

quote:
Originally posted by Rorso
The problem is the first %0 which copies the entire argument list of the alias into the translation. Here is how to solve it:
The new p2p alias:
#exec %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

How does this work? Well the first step is that we attempt to match the argument with the regular expression. It will copy the name of the target character to the variable p2pName. Then it'll copy the message to the p2pMessage variable. We then send the message to the translation function.

Good luck Smile



Ok. I must be doing something wrong... Here's what I've got now...


ALIAS
p2p

Value
#exec %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

I'm getting this returned to the MU*
0
p2p = Mmmmm?


Any idea why it's not working?

Thanks,
Tygerhart


Ok I guess I made some errors Very Happy.

ALIAS
p2p

Value
#noop %regex( %0, "([a-zA-Z]+)=(.*)", p2pName, p2pMessage)
~p2p @p2pName=%subregex( @p2pMessage, "(r|R)|(m|M)", "@translate(~%0, %random(3,4))") Mmmmm?

Then the syntax to use this alias is:
p2p PlayerName=Message

Example:
p2p John=Hello how are you?
Reply with quote
Tygerhart
Novice


Joined: 04 Oct 2001
Posts: 43
Location: Canada

PostPosted: Sat Feb 07, 2004 2:22 pm   
 
quote:
Originally posted by Rorso

Then the syntax to use this alias is:
p2p PlayerName=Message

Example:
p2p John=Hello how are you?



It works like a dream! Thanks I owes ya 2 now. Very Happy

Thanks again,
Tygerhart
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Feb 07, 2004 5:04 pm   
 
Since the problem was that %0 provides the entire argument list, it would have been simpler to just replace %0 with %-2 which provides the entire argument list EXCEPT for the first argument.
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sat Feb 07, 2004 6:27 pm   
 
quote:
Originally posted by LightBulb

Since the problem was that %0 provides the entire argument list, it would have been simpler to just replace %0 with %-2 which provides the entire argument list EXCEPT for the first argument.


That would probably not have worked because of the equal(=) sign and no requirement to have spaces on any of its sides.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Feb 07, 2004 10:28 pm   
 
quote:
Originally posted by Rorso

quote:
Originally posted by LightBulb

Since the problem was that %0 provides the entire argument list, it would have been simpler to just replace %0 with %-2 which provides the entire argument list EXCEPT for the first argument.


That would probably not have worked because of the equal(=) sign and no requirement to have spaces on any of its sides.


Sorry Rorso. I know how frustrating it can be to put hours into solving a problem only to have someone else point out a simpler way. However, that's an unusual assertion to make, particularly without testing, and I'm fairly certain you're mistaken. The original alias clearly worked despite "the equal(=) sign and no requirement to have spaces on any of its sides", with two minor problems directly related to the use of %0. The only change I suggested is to replace %0 with %-2, which will eliminate both of those problems. I don't understand why you think this "would probably not have worked" since it's just replacing one system variable with another. However, as I'm not using a beta version, I don't have the %subregex function to test it myself.

This uses the same syntax as the original alias
p2p peter I'm making a card.
and, despite Rorso's negative comments, should work.

ALIAS
p2p

VALUE
~p2p %1=%subregex( %-2, "(r|R)|(m|M)", "@translate(~%-2, %random(3,4))") Mmmmm?

NOTES:
1. The first problem was that changes were being applied to the first word following the parameter. This was caused by the use of %0. %0 is an undocumented system variable which provides the entire parameter string of an alias, including the first word. %-2 is a documented system variable which provides the entire parameter string of an alias, beginning with the second word and therefore not including the first word.
2. The second problem was that the unmodified text, beginning with the second word, was appended to the string following the modified text. This was also caused by the use of %0. Any text following the aliasname that is not used as a parameter is appended to the results of the alias expansion by #ALIAS. %0 does not count towards "used text" so the original alias only counted the first word, referred to by %1, as "used" and appended the remaining "unused text", which caused "I'm making a card." to be displayed twice. %-2 does count towards "used text" and leaves no "unused text" to be appended.
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sat Feb 07, 2004 10:55 pm   
 
quote:
Originally posted by LightBulb
Sorry Rorso. I know how frustrating it can be to put hours into solving a problem only to have someone else point out a simpler way.

Sorry if I seemed angry Very Happy. I was a bit tired when I replied.

However I realize my mistake now. I thought the syntax Tygerhart wanted to use with the alias was the following:
"p2p username=message"

While in reality he wanted to use:
"p2p username message"

In that case %-2 clearly works as you said as there isn't any '=' sign making it into one argument. However I still didn't know %-2 could be used and would probably have used another method and I'm glad you showed an alternative way to do it.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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