|
Quilana Beginner
Joined: 10 Jan 2008 Posts: 13
|
Posted: Mon Aug 08, 2011 3:03 am
%1 contains this letter |
In my mud the prompt looks something like this...
496h, 528m, 462e, 0p elrx-
At the end of the prompt are a bunch of letters meant to signify that I have some kind of balance or defense (or to tell me when I am prone)
If I make it so that it is caught with ([erlxpk]) I wind up with %1 = elrx
Is there any type of function or any other means of doing something like
IF %1 contains [letter]
Do this |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Mon Aug 08, 2011 3:12 am |
Try the %pos function.
|
|
|
|
Quilana Beginner
Joined: 10 Jan 2008 Posts: 13
|
Posted: Mon Aug 08, 2011 4:18 am |
Alright. I've tried it like this
if (%pos(p,%1)=>1) {stand}
but it's not compiling.
Suggestions? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Aug 08, 2011 4:27 am |
Use the command character. #if, not if.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Quilana Beginner
Joined: 10 Jan 2008 Posts: 13
|
Posted: Mon Aug 08, 2011 4:31 am |
Pardon me. That was a C/P error. It is '#if', not 'if'.
I've also tried
$temp = %pos(p,%1)
#if ($temp=>1) {stand} |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Mon Aug 08, 2011 4:46 am |
Not sure what you're trying to accomplish with "=>" but if you wanted 'greater than or equal to' you need to type it as ">=" The first one will cause a compilation error.
|
|
|
|
Quilana Beginner
Joined: 10 Jan 2008 Posts: 13
|
Posted: Mon Aug 08, 2011 8:45 am |
Blah. Still not working.
This is the trigger:
^%dh, %dm, %de, %dp ([elrxkp])-
This fires correctly and was checked with an echo in the value.
Both #if (%pos(p, %1)>=1) {stand}
and #if (%pos(p, %1)~=0 && %pos(p, %1)~=false) {stand} {}
do NOT work.
This is what it is firing off of:
574h, 642m, 624e, 0p elrxp-
To debug I attempted to check for both p (which IS in the string) and k (which is NOT in the string)
#echo %pos(k, %1)
and
#echo %pos(p, %1)
Both of these Echoed '0' |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon Aug 08, 2011 2:16 pm |
If you want it to match only when true, you don't need to add the >=1 bit.
Code: |
#IF (%pos("p",%1)) {stand} |
should work.
You really should put strings in quotation marks, too, so CMUD knows you're attempting to match a string, not a variable or anything else. |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Mon Aug 08, 2011 3:45 pm |
I'm not even sure how that regex is matching with that input to be honest. ([elrxkp])- <-- You are matching only a single character followed by a hyphen with this. Change that to ([elrxkp]+)- and see if your code starts doing what you expect.
|
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Mon Aug 08, 2011 5:16 pm |
orphean wrote: |
I'm not even sure how that regex is matching with that input to be honest. ([elrxkp])- <-- You are matching only a single character followed by a hyphen with this. Change that to ([elrxkp]+)- and see if your code starts doing what you expect. |
He's using a CMUD trigger pattern not regex.
Secondly going with the %pos function you were pointed to %pos(p,s), p should be the pattern you want to return the position of elrx is what I think you were trying to match? And s should be the string %1. so the trigger below will work if you feed CMUD the string below.
Code: |
#show {496h, 528m, 462e, 0p elrx-} |
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="10" copy="yes">
<pattern>^%dh, %dm, %de, %dp (["elrxkp"])-</pattern>
<value>#if (%pos("elrx",%1)) {#send stand}</value>
</trigger>
</cmud>
|
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Mon Aug 08, 2011 9:56 pm |
Ah well that explains that then regarding the pattern. But all those letters won't appear on the prompt all the time, that's just all possible letters. On IRE muds they tell you stuff like if you're prone, have equilibrium, are balanced, etc. From what I can see in that code doesn't it assume that 'elrx' will always be there no matter what? Anyway this is how I would do it with a regex:
Code: |
<trigger name="Test" priority="27730" regex="true" id="2773">
<pattern>^\d+h, \d+m, \d+e, \d+p ([elrxkp]+)-</pattern>
<value>#show %if( %pos(e, %1), "Has", "Does not have") E
#show %if( %pos(l, %1), "Has", "Does not have") L
#show %if( %pos(r, %1), "Has", "Does not have") R
#show %if( %pos(x, %1), "Has", "Does not have") X
#show %if( %pos(k, %1), "Has", "Does not have") K
#show %if( %pos(p, %1), "Has", "Does not have") P
</value>
</trigger> |
Given the string below as input,
Code: |
#show {496h, 528m, 462e, 0p elrxp-} |
Will give us the following output.
Code: |
Has E
Has L
Has R
Has X
Does not have K
Has P |
|
|
|
|
|
|
|
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
|
|