Metis - Guide 3 - Operators



Operators
Operators are easy to use and very, very useful if you know them well and what each can do.  They are like the backbone to creating any useful script as you can manipulate data, either digits or strings of characters.

Explaining Each Operator
All operators are used in the same sort of way.
<out type="push" extdata="VariableName"><operator bit goes here/></out>
Now I will go through each operator and explain what each does and how to use it.

Addition/Subtraction/Division/Multiplication
<operator type="+" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="-" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="/" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="*" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>

All of these work the same way.  Performing the calculation as if it were a calculator.
Note:- Metis does NOT like decimals.  You must use whole numbers.  Read the guide on useful workarounds for some tips to avoid this.

Increment/Decrement
<operator type="++" lvalue="%USERVAR[value1]%"/>
<operator type="--" lvalue="%USERVAR[value1]%"/>

This is an easy way to add 1 or subtract 1 from a figure.  This works the same as addition and subtraction it just presumes value2 is 1.
Note:- In some older versions of Metis these are major bugs so I still tend to do this as a normal addition or subtraction with the figure 1.

Modulo
<operator type="%" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This is the same as division, only instead of returning the integer it returns the remainder.

To The Power
<operator type="^" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This raises value1 to the power of value2, so if value1 was 4 and value2 was 3 then the sum would be = 4x4x4.

Not Logical
<operator type="!" lvalue="%USERVAR[value1]%"/>
This returns either a 1 or a 0 dependant on if value1 is true or not.  If it is true the returns 0 if it is false then returns 1.  I personally have never ever used this operator, not really sure why anyone would need to, but its there in case!!!

And/Or
<operator type="aa" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="||" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>

Both are very similar, again they return either a 1 or a 0.  The and operator (aa) returns 1 if value1 and value2 are true, else returns 0.  The or operator (||) returns 1 if either value1 or value2 are true if both are false it returns 0.

Equal/Not Equal
<operator type="==" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="!=" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>

Both are once again very similar, again they return either a 1 or a 0.  The equal operator returns 1 if value1 is the exact same as value2, else returns 0.  The not equal does the complete opposite.

Greater/Smaller
<operator type=">" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
<operator type="<" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>

The greater operator returns a 1 is value1 is bigger than value2, otherwise a 0.  The smaller operator does the same thing but the other way round.

That�s all the numerical operators, now we move onto the string operators.

String Length
<operator type="strlen" lvalue="%USERVAR[value1]%"/>
This operator measures the length, in characters (even spaces count as 1) of value1.

String Trim
<operator type="strtrm" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This operator trims value1 to the length (in characters) of value2 i.e. value1 = #c7#R��k�#c1#f룣� #c8#�k��K, while value2 = 10, then the result would be #c7#R��k�#.

String Lower/Upper
<operator type="strlwr" lvalue="%USERVAR[value1]%"/>
<operator type="strupr" lvalue="%USERVAR[value1]%"/>

These operators make a string of letters/digits either all uppercase or lowercase.

String Left
<operator type="strleft" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This is used to manipulate strings to cut them down, such as the rawname of a user and cut off the ID numbers.  Normally used in conjunction with strlen.  It cuts up value1 from the left hand side into a string of value2 characters long.

String Right
<operator type="strright" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
Similar to strleft, this operator cuts up value1 taking everything to the right hand side of the character value2, where value2 is a number.  An example would be to take a roomname as value1, including the hash.  You need to do strlen to work out the entire length then subtract 12, this is now value2.  When you strright it you will be storing the hash number only in the variable.

String Concatenate (Combine)
<operator type="strcat" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This operator combines value1 with value2 to make a long string.  An alternative is to try
<out type="push" extdata="VariableName">%USERVAR[value1]%%USERVAR[value2]%</out>

String Remove
<operator type="strrem" lvalue="%USERVAR[value1]%" rvalue="%USERVAR[value2]%"/>
This operator removes any occurrences of value2 out of the string value1.  This is very useful but be warned that you need to be very specific as you could remove parts you didn�t mean to i.e. value1 = #c7#R��k�#c1#f룣� #c8#�k��K000_12345, value2=1 this would remove the character "1" from the first string in all places including the colour code.  This would end up looking like #c7#R��k�#c#f룣� #c8#�k��K000_2345

String Replace
<operator type="strrep" nvalue="%USERVAR[value1]%" lvalue="%USERVAR[value2]%" rvalue="%USERVAR[value3]%"/>
This operator is very similar to strrem but instead of removing the string it replaces it.  So value1 would be the full string, value2 is the character you want to get rid of and value3 is the new character that will be inserted.

There are 2 more operators, they read file or web pages.  I have never really found any real use for the web one as I found a program called 'wget' that did the same thing long before the web reader was added to Metis.  Even then it is only so good as it reads the webpage�s source so you need to remove any html etc codings e.g. '<b> <br>'.

Read File (.txt)
<operator type="readfile" nvalue="%USERVAR[value1]%" lvalue="%USERVAR[value2]%" rvalue="%USERVAR[value3]%"/>
This operator reads the file value1 (where value1 is the full path and filename including the file extention e.g. C:\test.txt).
Value2 is the reading type.  This can be either a single line or and entire section, type "l" is the line where value3 is the line number to be read, e.g. value2="l" value3="3" will read line 3.  The entire section, or continuous, type is represented as �c".  with this you can specify how many lines from 1 you want to read, where value3 is the number of lines, e.g. value2="c" value3="5" will read the first 5 lines, or value2="c" value="-1" will read the entire file.

Read Web
<operator type="readweb" nvalue="%USERVAR[value1]%" lvalue="%USERVAR[value2]%" rvalue="%USERVAR[value3]%"/>
This operator is almost the same as readfile, only difference is the nvalue is a url not a filename etc.  so instead of nvalue="C:\test.txt" it would be nvalue=" http://www.therebelion.nr.com/".


Use these to help you get information that is easily read into the format you want, by trimming, replacing, removing and adding.  Read on for the next section.


Guide 4: Advanced Commands[Coming Soon]

©2005-2024 WinMXWorld.com. All rights reserved. Page last updated Sun Feb 17 2008