|
RadTopHat Newbie
Joined: 20 Dec 2010 Posts: 3
|
Posted: Mon Dec 20, 2010 9:47 am
Problems with script using IF to match text string variables |
Okay, basically I am make a stat roller.
Here is a copy of the standard output for stats from the mud which should now be BOLD and GREEN
Reroll!
STR : You have a well-defined, muscular physique.
DEX : You are nimble and flexible.
INT : You have an average intelligence.
WIS : You usually make sound decisions.
CON : You are in good health.
CHR : You are popular.
Do these stats look satisfactory to you? [y/n]:
Now they don't give you the actual number values, just various text strings to determine rough stats for you to decide. The following is a copy of the XML code for the script I am using to try and turn the text strings into variables and then match them to the IF statement in order to determine the Y / N value.
Code: |
<trigger priority="1320" enabled="false" id="132">
<pattern><![CDATA[Reroll!
STR : &STR
DEX : &DEX
INT : &INT
WIS : &WIS
CON : &CON
CHR : &CHR
Do these stats look satisfactory to you?]]></pattern>
<value>%if((@STR=You have the strength of the Gods.) AND (@DEX=Your dexterity allows you to laugh at danger.) AND (@INT=You have the intelligence of all the known libraries.) AND (@WIS=You have the wisdom of the ages.) AND (@CON=You have the constitution of the mountains themselves.),y,n)</value>
</trigger> |
Now I removed the [y/n]: from the final line of my pattern as it was causing me issue trying to get it to match.
Basically this script does not launch at all. If I reduce it to a single IF based on one stat ie.
Code: |
%if(@CON=You have the constitution of the mountains themselves.,y,n)
|
Then the script will launch however regardless of text displayed on screen, it never matches and I only get an N response.
Am I using the wrong type of variable here or what? Any help you could over would be appriecated.
Thanks |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Mon Dec 20, 2010 1:25 pm |
Code: |
<trigger priority="1320" id="2">
<pattern>Reroll!</pattern>
<trigger>
<pattern>STR : &STR</pattern>
<value>#beep</value>
</trigger>
<trigger>
<pattern>DEX : &DEX</pattern>
</trigger>
<trigger>
<pattern>INT : &INT</pattern>
</trigger>
<trigger>
<pattern>WIS : &WIS</pattern>
</trigger>
<trigger>
<pattern>CON : &CON</pattern>
</trigger>
<trigger>
<pattern>CHR : &CHR</pattern>
</trigger>
<trigger>
<pattern>Do these stats look satisfactory to you? ~[y/n~]: </pattern>
<value>#if ((@STR =~ "You have the strength of the Gods.") AND (@DEX =~ "Your dexterity allows you to laugh at danger.") AND (@INT =~ "You have the intelligence of all the known libraries.") AND (@WIS =~ "You have the wisdom of the ages.") AND (@CON =~ "You have the constitution of the mountains themselves.")) {#send y} {#send n}
</value>
</trigger>
</trigger> |
That should work.
Here are a few things that may help you in the future. %if is a function #if is a command start lines in your scripts with commands. Your [y/n] was causing problems most likely because it was not properly quoted.
If you do not quote [ and ] in patterns with the ~ character CMUD will treat what is between them as a range. Also when trying to match strings directly, they need to be quoted.
Hope that helps some |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
RadTopHat Newbie
Joined: 20 Dec 2010 Posts: 3
|
Posted: Wed Dec 22, 2010 8:07 pm |
Hey Fizgar,
Thanks for the info helped a lot getting the script to work. FYI the modified code you posted didn't quite work as is, I created a new trigger and pasted your code into the XML. When ran on the first go through I would receive the BEEP notification however it would not supply a Y or N, which obviously was the main point, and after the first go it would not BEEP at all.
What I did was break it down and run through some testing adding variable by variable. First thing I found was I needed to remove the extra space after the ~ and before the " ie. =~ " turned into just =~" from there everything was fine until I got to using the last section of the prompt which has two blank lines before the final question with the [ Y / N ?]
CHR : You are popular.
Do these stats look satisfactory to you? [y/n]:
This is where the script fails to kick over. Here is the code I ended up going with...
Code: |
<trigger priority="1320" id="221">
<pattern>Reroll!</pattern>
<trigger>
<pattern>STR : &STR</pattern>
</trigger>
<trigger>
<pattern>DEX : &DEX</pattern>
</trigger>
<trigger>
<pattern>INT : &INT</pattern>
</trigger>
<trigger>
<pattern>WIS : &WIS</pattern>
</trigger>
<trigger>
<pattern>CON : &CON</pattern>
</trigger>
<trigger>
<pattern>CHR : &CHR</pattern>
<value>#IF ((@STR =~"You have the strength of the Gods.") AND (@DEX =~"Your dexterity allows you to laugh at danger.") AND (@INT =~"You have the intelligence of all the known libraries.") AND (@WIS =~"You have the wisdom of the ages.") AND (@CON =~"You have the constitution of the mountains themselves.")) {#send y} {#send n}</value>
</trigger>
</trigger> |
All in all it works which is the aim, but its not quite perfect. Thanks for the assist. |
|
|
|
|
|