 |
hezukeh Beginner
Joined: 24 Sep 2004 Posts: 14
|
Posted: Tue Sep 28, 2004 7:01 pm
string search |
Ok, how would you search for specified text within a string? (MM2k's @StrStr procedure) For instance:
Lets say that "@textvar==whatever". You want to check to see if whatever includes "ate". It returns 1 for true, 0 for false or whatever.
#if (%?function?(@testvar,"ate")==1) {do this} {do that} |
|
|
 |
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Tue Sep 28, 2004 7:43 pm |
You might want to look a bit in the help file of zMUD. I dislike to recommend people to do that but in this case it is an easy problem to solve using the documentation.
try: #echo %pos("ate", @testvar) |
|
|
 |
TonDiening GURU

Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Tue Sep 28, 2004 7:48 pm |
You are looking to see if something is in something, so you can check to see if the position of that string is 0 (not in) or greater than zero (is in).
#IF (%pos("ate",@testvar)>0) {
#SHOW ate in '@testvar'} {#SHOW ate not in '@testvar'} |
|
|
 |
hezukeh Beginner
Joined: 24 Sep 2004 Posts: 14
|
Posted: Tue Sep 28, 2004 8:26 pm |
ty, also got another question: what can i use to get the color of a string. For example:
if (%?function?(@testvar) == %ansi(bold, red)} {DO this} {do that}
Yeah i've been looking through help files but it's kind of hard to find stuff if you don't know exactly what you're looking for :P |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Sep 29, 2004 1:11 am |
Capturing ansi is somewhat tough in zMud. In general it is better to just let the pattern take care of comparing the color. Ansi trigger are nearly always created in the Settings Editor. The steps to do this are:
Highlight the line of text you want to use for the trigger
Press CTRL-C to copy the text
Open the Settings Editor
Select New|Trigger from the top button bar or the Edit menu.
Click on the Options tab
Select ANSI trigger
Click on the Pattern tab
Click in the pattern box
Press CTRL-V to paste the text
Your pattern should contain some sequences like %e[32m in it. These are what detect the color. You can edit this pattern now to eliminate portions of the line you don't need to check for or use wildcards as described in the Pattern Matching help page. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
hezukeh Beginner
Joined: 24 Sep 2004 Posts: 14
|
Posted: Wed Sep 29, 2004 2:24 am |
Hrm ok, ty. But now lets say i wanted to get the color of HP in the prompt for Medievia because depending on your health the color changes. How would I do something like that where different items will be different colors?
Actually i think i figured something out:
Code: |
#action {<(&hp)hp (&mp)mp (&mv)mv (&br)br>} {#if (%pos(%ansi(132),@hp)>0) (#var hp %ansi(bold,red)@hp} {if |
--> etc check all the necessary colors, then do the same for mp, mv, and br
Here's how I figured figured it out since I'm frozen atm:
Code: |
#show %pos(%ansi(132),%ansi(bold,red)hp) |
Here's how I got the color number:
Code: |
#show %eval(%color(bold)+%color(red)) |
Edit: Or something you mentioned about the [32m and what not, try using pos to find that. |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Sep 29, 2004 3:55 pm |
The colors aren't important. They just reflect the results of some mathematical calculations. You can perform the same calculations that Medievia does and base your actions on the results. Even better, you can perform different calculations so you don't have to depend on Medievia to decide the right percentages to do things.
#TR {(%n)/(%n)hp} {#IF ((%1 * 4) <= %2) {#SAY Low health! 25~% or less} {#SAY Good health! Over 25~%}} |
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
 |
hezukeh Beginner
Joined: 24 Sep 2004 Posts: 14
|
Posted: Wed Sep 29, 2004 6:55 pm |
Yes i know, but if you take the color directly from the text it reduces the work you have to do. Instead of making it look for the max amount and compare the two, it will just return the value.
|
|
|
 |
|
|