7/21/08

III: Operators

Introduction


Addition, Subtraction, Multiplication and Division and other math operations can only be done in numeric values and if you try it with strings you will get error and script will not run.

Basic Operators



+ -- Addition
- -- Subtraction
* -- Multiplication
/ -- Division

Simple Addition


Examples:
/run x=1+2 SendChatMessage(x)
This will say in chat
3

Simple Subtraction


/run x=10-6 message(x)
This will make a window with this message:
4


Simple Multiplication:


/run x=1*2 message(x)

This will open a window with message:

2

Simple Division

/run message(50/10)
This will open a window with message:
5

Simple multiple operators

/run x=(10-4)*3 message(x)

This will make a window with this message:

18
Note: you can also add it directly as a parameter to a function, it is not necessary to make an operation on a variable, BUT if the value is used TWICE or more in the script, make it a variable instead of direct ly using it as parameter

Function Operations


Using operators for functions is the same as using them on variables, just a lil bit confusing tho.

Getting HP % of your character

/run p="Player" h=UnitHealth(p)*100/UnitHealthMax(p) message(h.."% HP")
This will create a window with of your health % like:

100% HP

No comments: