TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Pattern matching on a line that can vary quite a bit

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
elminster



Joined: 13 Jul 2009
Posts: 46

PostPosted: Mon Jan 09, 2017 1:28 pm    Post subject: Pattern matching on a line that can vary quite a bit Reply with quote

I have a number of abilities that I can turn on or off, and a line that shows which ones are active. Next to them, there is a number of how long until they expire. So, say I have 6 things active, I will see something like this:

Actives: 6 => Ap: 4840 IV: 1168 Iv: 1305 AA: 1229 IB: 1302 bc: 792

For some explanation, IV has 1168 rounds until it expires, etc.

I'm not clever enough to do this easily, and my captures for this are huge. One action for each possible set of "actives" , right now for just 1-8, but sometimes I need more than that. To make things more confusing, they will not always be in the same place on the line. So I make huge piles of IF statements, like if %1 = Ap then this, if %3 = Ap then this for each and every one, making the higher end number of Actives just big... It seems so messy and badly done. So...

The general idea is that there will be 1-3 characters (number or letters) on the left, followed immeiately by a colon, then a space, then a set of characters on the right, that will be a combo of letters and numbers (in my example here you just see numbers). They are a pair though, and I want to capture them as a pair. Like, IV (the power) and IVremaining (the number after).

Is it possible to set a single action that could capture all of this? I'll put some more examples here...


Actives: 8 => Ap: 4840 IV: 868 Iv: 1005 AA: 929 IB: 1002 Eb: 1783 ab: 1778Smo bc: 872

Actives: 9 => Ap: 4840 IV: 848 Bo: 1124 Iv: 985 AA: 909 IB: 982 Eb: 1763 ab: 1758Smo bc: 850


In these examples every "power" shows just two letters, but they can sometimes have a number, like AC4.

Thanks for looking, and thanks for any help!


Edit: I would also like to mention, no problem making a new action for each number currently active. I would just like to know a way to identify the currently actives with remaining info in a single stroke rather than many lines of IF.
Back to top
View user's profile Send private message AIM Address
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Tue Jan 10, 2017 2:02 pm    Post subject: Reply with quote

This will put all the values in a #LIST, so you can do what you want with them

Code:

#ACTION {Actives: %d =>%*}
{
   #VAR {ConvString} {%2};
   #REPLACE ConvString {{ }{.[^:]}} {;&2};
   #REPLACE ConvString {:} {;};
   #REPLACE ConvString {{^;}} {};
   #LIST Values CREATE $ConvString;
   #FOREACH $Values[] count {#ECHO {$Values[$count]}}
}


Code:

#show {Actives: 9 => Ap: 4840 IV: 848 Bo: 1124 Iv: 985 AA: 909 IB: 982 Eb: 1763 ab: 1758Smo bc: 850}

Ap
4840
IV
848
Bo
1124
Iv
985
AA
909
IB
982
Eb
1763
ab
1758Smo
bc
850


EDIT:

You can use this kind of trick to search for values on the list:

Code:

#FUNCTION SearchList
{
   #LIST Values FIND {%1} index;
   #IF {$index>0}
   {
      #MATH index2 {$index+1};
      #RETURN $Values[$index2]
   }
   {
      #RETURN 0
   }
}


Code:

#echo {@SearchList{Iv}}
985
#echo {@SearchList{IV}}
848
#echo {@SearchList{Ap}}
4840


EDIT:

And for completeness you can use this to know the active effects on the list:

Code:

#FOREACH $Values[] count {#IF {$count%2!=0} {#ECHO {$Values[$count]}}}
Ap
IV
Bo
Iv
AA
IB
Eb
ab
bc
Back to top
View user's profile Send private message
elminster



Joined: 13 Jul 2009
Posts: 46

PostPosted: Tue Jan 10, 2017 6:36 pm    Post subject: Reply with quote

Thanks again PowerGod. I was able to use this to get exactly what I wanted. If we ever cross paths I owe you a beer!
Back to top
View user's profile Send private message AIM Address
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Jan 11, 2017 4:14 am    Post subject: Reply with quote

Code:

#path save forward {ToTheBeer}


LOL, I'm happy you found it useful Smile
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Sat Jan 14, 2017 12:59 pm    Post subject: Reply with quote

One alternative that is a little simpler and faster is this.

Code:

#ACTION {Actives: %d =>%*}
{
    #var Values {%2};

    #replace Values { %S: %S} {{&1}{&2}}
}


Then

Code:
#showme $Values[Ap]


should print the Ap value.

#showme $Values[] will print all the captured effects.
Back to top
View user's profile Send private message Send e-mail
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Sat Jan 14, 2017 6:02 pm    Post subject: Reply with quote

This is indeed faster, no need to "find" values, and that replace trick is cool, I'll have some use for it !!

But to list all the captured effects maybe this is better (I always have issues when dealing with "{}" in strings)

Code:

#foreach $Values[] count {#echo {$count}}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group