View Single Post
07-31-13, 01:53 AM   #1
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
Saving values to different tables in a loop.

I'm trying to go through each mount a player has and add that to a table "flying", "ground" or "aquatic" within the table "mounts". With the code I currently have it, it doesn't add them to a table.

However, if I take out the bit of code to add to ground or aquatic (the elseifs) and have it just add to the flying table it works just fine (and I don't think it's just the flying in particular, but rather I can only add to one sub-table rather than multiple ones).

Is there an error in my code or is it just not possible with this approach?


Lua Code:
  1. local mounts = {}
  2.     mounts.flying = {}
  3.     mounts.ground = {}
  4.     mounts.aquatic = {}
  5.  
  6. local amount = GetNumCompanions("mount")
  7.  
  8. local f, g, a = 1
  9.  
  10. for i = 1, amount do
  11.     local creatureID, creatureName, creatureSpellID, icon, issummoned, mountType = GetCompanionInfo("mount",i)
  12.    
  13.     if mountType == 7 or mountType == 15 or mountType == 23 or mountType == 31 then
  14.         mounts.flying[f] = {creatureID, creatureName, creatureSpellID, icon, issummoned, mountType}
  15.         --print(mounts.flying[f][2])
  16.         f = f + 1
  17.     elseif mountType == 29 then
  18.         mounts.ground[g] = {creatureID, creatureName, creatureSpellID, icon, issummoned, mountType}
  19.         --print(mounts.ground[g][2])
  20.         g = g + 1
  21.     elseif mountType == 12 then
  22.         mounts.aquatic[a] = {creatureID, creatureName, creatureSpellID, icon, issummoned, mountType}
  23.         --print(mounts.aquatic[a][2])
  24.         a = a + 1
  25.     end
  26. end
  Reply With Quote