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, 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.
 Entire forum ➜ MUSHclient ➜ General ➜ Replacing words and phrases in commands

Replacing words and phrases in commands

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


Posted by Vercalos   (23 posts)  Bio
Date Wed 14 Sep 2011 11:21 PM (UTC)
Message
Is there any way of taking a command, sending

A B C B B C B

and replacing every instance of B in the command with -B-?

I'm trying to make an alias to automatically insert ANSI into anything between "", rather than making a seperate alias for A "B", "B", A "B" C "B" and so on.
Top

Posted by Daniel P   USA  (97 posts)  Bio
Date Reply #1 on Wed 14 Sep 2011 11:47 PM (UTC)
Message
Look at string.gsub()

Example used in the help file:

string.gsub ("nick eats fish", "fish", "chips") --> Nick eats chips


In your case:

string.gsub("A B C B B C B","B","-B-")
Top

Posted by Vercalos   (23 posts)  Bio
Date Reply #2 on Thu 15 Sep 2011 12:40 AM (UTC)
Message
So would that work for when I send commands?

And that means writing a script?
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 15 Sep 2011 09:28 PM (UTC)
Message
You would write an alias - that matches something. Then inside the alias do "send to script" and do something like string.gsub to replace things. Then do a Send (results) to send the replaced text to the MUD.

You need to get the string.gsub right, eg. you may not want to replace letters inside other words, for example.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Vercalos   (23 posts)  Bio
Date Reply #4 on Fri 16 Sep 2011 04:46 AM (UTC)
Message
Nick Gammon said:

You would write an alias - that matches something. Then inside the alias do "send to script" and do something like string.gsub to replace things. Then do a Send (results) to send the replaced text to the MUD.

You need to get the string.gsub right, eg. you may not want to replace letters inside other words, for example.

Well my main concern goal is to make commands go from

"A" B "C" to "[ansi(*,A)]" B "[ansi(*,C)]"

Without adding ansi tags to B, etc.
Top

Posted by Nick Gammon   Australia  (23,057 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 16 Sep 2011 06:00 AM (UTC)
Message
Can you give a more concrete example? Are A B and C words? Consisting of A-Z? Or digits as well? Will they have spaces in them?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Vercalos   (23 posts)  Bio
Date Reply #6 on Fri 16 Sep 2011 06:28 AM (UTC)

Amended on Sat 03 Dec 2011 04:02 AM (UTC) by Vercalos

Message
like turn
"I said I wasn't going to go," the man replied in a very annoyed voice, "you kill yourself if you want but I'm staying here!"

into
"[ansi(*,I said I wasn't going to go,)]" the man replied in a very annoyed voice, "[ansi(*,you kill yourself if you want but I'm staying here!)]"

Basically, I'm trying to automatically color speech in a MUSH.
<EDIT>


Hello?
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.


18,783 views.

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.