9/25/08

Global Variables

Introduction

Variables, as I said in my variable tutorials , have two kinds, a global and a local variable.

And yes, you can guess it there diffrence by there name. Global variables will retain it's value after the script, while the local variables will be nil after the script.


Usage


As you might have guess, using global variables will be useful for storing information specially when you are trying to make a macro that will depend in every click.
For example, you can make a macro that counts like a lil child like this
/run if x==nil then x=1 else x=x+1 end SendChatMessage(x)


Characters


Unlike local variables, global can make WoW Addon errors. This is because if you declared a global variable that is same as an addon variable, it will record your declared variable as the new addon variable.

For example, if you made a global variable like DamageDone=100000000000000 and an add-on uses it on a damage meter, then your it will show you that the damage done is 100000000000000.

To prevent this problem,
  • Do not use unnecessary globals.

  • If you got enough space,Make global variables at least 3 characters long

  • Do not make global variables too readable. This kind of variables are often used in add-ons

  • If it still errors out your add-on, it's your add-on's fault. add-ons should have long global variables. This is because they do not have character limit unlike macros.


Now once you're good enough and proficient enough, you can now make
/run if x==nil then x=1 else x=x+1 end SendChatMessage(x)

into
/run if cou==nil then cou=1 else cou=cou+1 end SendChatMessage(cou)


Always make sure that your 3-character variable can still give a clue of what you want. For example, I made "cou" variable in above example to give a clue that it will be used in counting. Do not use "xxx" "yyy" or anything that won't give a definite clue because: When you are making alot of macros, you can accidentally replace your own variables.

2 comments:

Unknown said...

The color scheme you have chose is horrible.

Unknown said...

What an eyesore of a page