|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Thu Apr 15, 2010 1:59 pm
Trigger Question. Help converting String of characters to a list of words. |
Hoping one of the wise readers out there can help me with this question.
I am working on a trigger that will take a line like the one that follows and sort the last string of characters into the actual words they represent. Then put those words into a variable that I can then use to display the full meaning of the string.
Code: |
#HUD:********:C:L# fc,v,PS,B,CC,10,10,0,10.562,185,0.000,0.000,180,-,0.000,180,80,0,BdDSFs
|
B = Burning
d = Dug in
D = Destroyed
S = Shutdown
F = Fallen
s = starting up
The list of possible characters is pretty long so that is just a sample. The method does need to be case sensitive though.
Everything is storing fine until that last string. I can't seem to wrap my brain around a way to pull that from the pattern and then sub in the actual words that the letters represent
I'm hoping to just throw everything into a regular string list variable since that would print out nicely for how I plan to use this. Nothing needs to be sorted, I just want a word for each letter.
Don't wanna make a huge post with everything I've tried this morning. So if anyone can offer a little help I would be very thankful. |
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: Thu Apr 15, 2010 4:13 pm |
Is the rest of the string preceding the info you want formatted the same way every time?
|
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Thu Apr 15, 2010 4:18 pm |
no, everything is constantly changing.
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Thu Apr 15, 2010 8:06 pm |
how long is the list of possibilities?
to use a string list var and have it be case sensitive for the initial letters... you could do this... dont laugh, it works...
i replaced %1 with the actual list for use on command line... so $x = BdDSFs would be $x = %1 in a trig...
enter this at command line,
{$list=%null;$x = BdDSFs;$x=%concat("X",$x);#LOOP %len($x) {$list = %concat($list,"|", %left(%right($x,%i),1))};$list = %replace(%replace(%replace(%replace(%replace(%replace($list,"|B|","|Burning|"),"|d|","|Dug in|"),"|D|","|Destroyed|"),"|S|","|Shutdown|"),"|F|","|Fallen|"),"|s|","|starting up|");$list = %leftback(%right($list,1),1);#show $list}
$list winds up being:
Burning|Dug in|Destroyed|Shutdown|Fallen|starting up
dunno, maybe it'll help ya think :P
I'm REALLY missing cAsE sensitivity in list vars :( |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Apr 15, 2010 8:40 pm |
Even though Zugg has asked us to keep it zscript, this case calls for a regex, and I think it's exactly what you're looking for:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="295160" regex="true" copy="yes">
<pattern>#HUD.+,(?:([BdDSFs]+))\s?</pattern>
<value>$replacement={%if( %pos( "B", %1), "Burning|")%if( %pos( "d", %1),"Dug in|")%if( %pos( "D", %1), "Destroyed|")%if( %pos( "S", %1), "Shutdown|")%if( %pos( "F", %1), "Fallen|")%if( %pos( "s", %1), "Starting up|")}
#PSUB {%leftback($replacement, 1)} %x1</value>
</trigger>
</cmud> |
This is, of course, assuming that the line will ALWAYS start with #HUD. Just continue to follow the format in the $replacement= part to add more as needed. Using that format, it changes:
Code: |
#HUD:********:C:L# fc,v,PS,B,CC,10,10,0,10.562,185,0.000,0.000,180,-,0.000,180,80,0,BdDSFs |
into
Code: |
#HUD:********:C:L# fc,v,PS,B,CC,10,10,0,10.562,185,0,0,180,-,0,180,80,0,Burning|Dug in|Destroyed|Shutdown|Fallen|Starting up |
and
Code: |
#HUD:********:C:L# fc,v,PS,B,CC,10,10,0,10.562,185,0.000,0.000,180,-,0.000,180,80,0,BdFs |
into
Code: |
#HUD:********:C:L# fc,v,PS,B,CC,10,10,0,10.562,185,0.000,0.000,180,-,0.000,180,80,0,Burning|Dug in|Fallen|Starting up |
and so forth.
Charneus |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Thu Apr 15, 2010 9:59 pm |
Thanks Charneus, the trigger you posted is working in the main window. Here is the actual trigger i'm wroking with right now.
Code: |
<trigger priority="3740" id="374">
<pattern>^#HUD:@HIKey:C:L# (*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*),(*)</pattern>
<value><![CDATA[#gag
#VAR CON_ID %1
#VAR CON_ARC %2
#VAR CON_SENSORS %3
#VAR CON_UnitType %4
#VAR CON_MechName %5 // - if unknown
#VAR CON_X %6
#VAR CON_Y %7
#VAR CON_Z %8
#VAR CON_Range %9
#VAR CON_Bearing %10
#VAR CON_Speed %11
#VAR CON_VertSpeed %12
#VAR CON_Heading %13
#VAR CON_JumpHeading %14
#VAR CON_RangeToCenter %15
#VAR CON_BearingToCenter %16
#VAR CON_Weight %17
#VAR CON_Heat %18
#VAR CON_Status %19
#switch (%match(@CON_MechName,CC (*))) {#var MechNameColor deepskyblue}
(%match(@CON_MechName,TC (*))) {#var MechNameCOlor Red}
Contacts:#mxp <c lime black>@CON_SENSORS</c> <c greenyellow black>@CON_ARC</c> <send 'Main:.l @con_id|Main:#send scan @CON_ID' Hint="Left Click to Lock Right Click for menu|Lock @Con_ID|Scan @Con_ID"><c @MechNameColor black><b>[@con_id] @CON_MechName</b></c></send><c lawngreen> X:<c Red>@CON_X<c lawngreen> Y:<c Red>@CON_Y<c lawngreen> Z:<c Red>@CON_Z</c> <c dodgerblue><b>R:</b> <c gold>%format(2,@Con_Range)</c> <c dodgerblue>B:</c> <c fuchsia>@CON_Bearing</c> <c dodgerblue><b>Sp:</b> <c chocolate>%format(2,@Con_Speed)</c> <c Dodgerblue>H: <c mediumspringgreen>@CON_Heading</c> <c dodgerblue><b>St:</b></c><c gold> @CON_Status</c>
Contacts:#show -
]]></value>
</trigger>
|
The trigger takes the info I want from line received then feeds it to a second window called contacts with mxp for color and clickable links. I used (*) in the pattern for simplicity for the time being. I would like to have all 19 variables stored. USUALLY I fail at regex but It looks I'm gonna give it another shot for this one. I need the practice anyway because it seems so useful.
Hopefully my monitors make it through the night, lol. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Apr 16, 2010 1:17 am |
Well, if you want all 19 variables stored, then you don't need the regex, you already have a trigger pattern that works. You just want to convert your Con_Status, right? Just use one of the replacement schemes that Private and Charneus used.
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Apr 16, 2010 1:58 pm |
It might even be a good idea to take my replacement script and put it into a function. Then you can do something like Con_Status=@makeword(%1). Then you'd be set.
Charneus |
|
|
|
|
|
|
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
|
|