View Single Post
08-02-13, 07:03 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
Right now you are (re)defining the variables on every loop, creating unnecessary garbage collection and a great deal of inefficiency.
Lua Code:
  1. local AllianceMammoth, HordeMammoth, GrandExpedYak = 61425, 61447, 122708
  2. for i = 1, numMounts do
  3.     if creatureSpellID == AllianceMammoth or creatureSpellID == HordeMammoth or creatureSpellID == GrandExpedYak then
  4.         tinsert(mounts.vendor, {i, creatureID, creatureName, creatureSpellID, icon, issummoned, mountType})
  5.     end
  6. end
Only the first line in the code you quoted creates variables that could be defined at the file level. The other 3 lines must be done inside the loop over all of the player's mounts, as all the variables it references do not exist outside the loop.

However, redefining 3 number values whenever COMPANION_UPDATE fires is hardly "a great deal of inefficiency", especially for the purposes of a beginner still trying to figure out the basic logic.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote