Quantcast WoWInterface - View Single Post - More than 200 local variables
View Single Post
02-11-20, 10:34 AM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,918
Originally Posted by Kanegasi View Post
Define a local table at the top of your addon and use keys instead of separate variables.

For example:

Lua Code:
  1. -- instead of this
  2. local a, b, c, d, e = 1, 2, 3, 4, 5
  3.  
  4. -- use this
  5. local vars = {}
  6. vars.a, vars.b, vars.c, vars.d, vars.e = 1, 2, 3, 4, 5
The entire appeal of using local variables aside from limiting scope is you save an index lookup in the global table. Putting variables in a local table completely negates this since you're re-adding the index operation you were trying to save.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote