|
Darkflame808 Beginner
Joined: 21 Sep 2010 Posts: 22
|
Posted: Fri Dec 17, 2010 7:56 am
Break up variable into smaller variables? |
Is it possible to take a string and break it up into smaller strings?
I'm trying to take a line of text and break it up into words.
For example I have a line that looks like this.
%[e32mA private commander (ansi color is yellow)
My goal is to make a MXP link for the individual words that does the command "exa"
#Trigger ^%e[32m {#show ok}
Will show "ok" on all lines that are yellow while skipping everything else which means i'm triggering only the proper lines however,
#Trigger ^%e32m(*) {#show %line} will show me the entire line "A private commander"
Creating a MXP link to %1 will show A private commander and send "exa A private commander" which fails on the mud.
Putting a trigger on (%w) and repeating in line will resolve my issue but it'll create links for every word in the mud and not just the ones on the orange lines.
Putting a trigger on ^%e[32m(%w) will create a link only to the first word on each line in which "exa a" will fail
Putting a trigger on %e[32m(%w) with "repeat within line" will only create a link to the last word of the line. "exa commander" works but for example An impoverished man will fail because the unique word is impoverished.
Is there a way to break up %line into (%w) (%w) (%w) (%w) (%w) ........and turn A private commander into A private commander from here I can click the unique word and have exa commander or exa private take effect.
Thanks! |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Dec 17, 2010 9:16 am |
Code: |
#LOCAL Output;#LOOP %numwords(%line, " ") {$Output=%concat($Output,"<send 'exa ",%word(%line, %i," "),"'>",%word(%line, %i," "),"</send> ")};#MXP $Output} |
Keep in mind that if you output it in the same color, it's going to go into an infinite loop. But that should work for you, anyway. |
|
|
|
Darkflame808 Beginner
Joined: 21 Sep 2010 Posts: 22
|
Posted: Fri Dec 17, 2010 4:57 pm |
Holy smokies that script has officially declared me a script kiddie. Lol
I'm going to %stripansi from the output because it was actually logging 0mA when I first started toying with my database. That should isolate any loops.
Thank you very much! I'll test it as soon as I get home. Have a wonderful day! |
|
|
|
Darkflame808 Beginner
Joined: 21 Sep 2010 Posts: 22
|
Posted: Fri Dec 17, 2010 9:16 pm |
Hey Charneus,
Thank you very much for your assistance!, Here was my final script for others to see if they ever run into the same situation.
Code: |
#trigger ^%e[33m
{
#gag
#LOCAL Output;#LOOP %numwords(%line, " ") {$Output=%concat($Output,"<send 'exa ",%word(%replace((%line),",",""), %i," "),"'>",%word(%line, %i," "),"</send> ")};#MXP $Output
}
|
It's exactly as you left it but I made a small adition of stripping out the , from the exa portion using the %replace function. I only know how to strip 1 character, not several so I chose , as that was the most common character used.
Thank you very much for taking the time to draw that up for me. Much appreciated! |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Dec 17, 2010 9:35 pm |
To strip out several characters, it's probably best to use %subchar, where you can do:
%subchar(%line, ",-.?!*")
and whatever other characters you come across. |
|
|
|
|
|
|
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
|
|