7/21/08

II: Variables

Introduction


using variables is essential to save characters and prevent overflowing to 255 character limit. Variable names may contain numbers or letters but must start with a letter. Normal variables will remain at there value except redeclared or replaced, until you log out.

Declaring a Variable


/run x=1
in this example, variable x will contain a value of 1

Using a Variable


/run x=1 SendChatMessage(x)
In this example it will say in chat:

1

FAQ: what if you call an undeclared variable?
it will return nil.
What is nil?
nil means null,none,nothing,void BUT NOT ZERO. Any usage, of undeclared variables as parameters will cause error and the whole script will not run.
nil is not called with quote wrap. It is used like a variable(without wraps)


Making string(non-numeric characthers) variables


/run x="Hello World" message(x)
Note: you will wrap strings with quote to make them variables

Making function variables.



Some functions returns values if they are used. Like UnitHealth("target") which returns the health of your target.
/run x=UnitHealth("target") message(x)
This will make a warning window with the health of your target. Note: you mustn't wrap it with quotes

Conjucting(connecting) variables


/run a="I" b="Am" c=UnitName("player")
To conjunct or connect variables or constants, just add double period and the next variable or constant
/run a="I" b="Am" c=UnitName("player") SendChatMessage(a.." "..b.." "..c)
Note that: you will still proper quotations

This will make you say in chat:
I am <yourname>

Redeclaring Variables


/run x=1 x=x+1 message(x)
Value will be: 2


Creating a local variable(stays only in that script)



Creating local variables are useful for macros that will not be used later. Declaring local variable will make the variable volatile, and that variable will be nil after the script is done
/run local msg="This is a local Variable, variable x will be nil after it is declared local and will also be nil after this script is over"
now after the macro, even you connect a "/run message(msg)" , it will not return the msg




No comments: