Quantcast WoWInterface - View Single Post - More than 200 local variables
View Single Post
02-09-20, 08:30 PM   #2
Kanegasi
A Firelord
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 482
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

You can even use the provided addon table in the second vararg return that's handed to each of your addon's files.

Lua Code:
  1. local addonName, addonTable = ... -- the very first line of your addon file

This addon table is shared across all your Lua files under a single .toc file.

I honestly wasn't aware of a local variable cap, but I've had tables with thousands of entries in them.

Last edited by Kanegasi : 02-09-20 at 08:35 PM.
  Reply With Quote