View Single Post
03/02/14, 04:36 PM   #7
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Okay, scratch the last reply.

It only works that way if I log in with an EMPTY!!!! Saved Variables table. Which totally defeats the point.


If I log in with an empty table that games session will correctly traverse the table ( maybe without the need for adding the history header table but I am not spending another half hour changing it back now ) but the moment I tell it not to clear the table out the old traverse problem returns.

By the way, what the heck is that version value for ? Should I set that to another value ?

Can some bright spark see what the heck I am doing wrong here or is it a bug in the SavedVariables table?

edit: As you can see this is annoying me to no end as I have wasted my beta weekend writing this addon and haven't been able to finish it because of this problem.

Here is my code in its entirety barring the Update routine being called from the XML as per the norm.
Lua Code:
  1. -- Values used often so created variables for them
  2. local addonName = "XrysGatherer"
  3. local addonVersion = "0.0.1"
  4. local addonSV = addonName.."_SavedVariables"
  5.  
  6. -- References to System and Manager objects
  7. local ChatMsg = CHAT_SYSTEM
  8. local EventMgr = EVENT_MANAGER
  9.  
  10. -- References to the Saved Variables Data
  11. local SVDefault = {}
  12. local SVData = {}
  13. local SVDataIndex = 0
  14.  
  15. -- Whether the player is currently interacting with something
  16. local interacting = false
  17.  
  18. -- Whether the player wants to view his history
  19. local showHistoryAtLogin = true
  20.  
  21. -- Initialise the Saved Variables File
  22. -- Found in EsoHead addon ( thanks )
  23. local function InitSavedVariables(...)
  24.     SVData = {
  25.         ["History"] = ZO_SavedVars:NewAccountWide("XrysGatherer_SavedVariables", 1, "History", SVDefault)
  26.     }
  27.     SVDataIndex = 1
  28. end
  29.  
  30. -- Check if the item already exists in the database in that zone and location ( or very close to it )
  31. -- Variation of the test found in Esohead addon ( thanks )
  32. local function SVDataExists(xPos,yPos,zone,name)
  33.     local found = false
  34.     local zoneData = SVData["History"][zone]
  35.     if not zoneData then return false end
  36.     local nameData = zoneData[name]
  37.     if not nameData then return false end
  38.     for i,v in pairs(nameData) do
  39.         local x,y = v["X"],v["Y"]
  40.         if math.abs(xPos - x) < 0.005 and math.abs(yPos - y) < 0.005 then
  41.             found = true
  42.             break
  43.         end    
  44.     end
  45.     if found then return true end
  46.     return false
  47. end
  48.  
  49. -- Update Routine to track harvest interactions which do not have an event at present
  50. function XrysGatherer_Update(...)
  51.  
  52.     -- Is the player interacting with something ?
  53.     local playerInteracting = IsPlayerInteractingWithObject()
  54.     if not playerInteracting then interacting = false return end
  55.  
  56.     -- Check if the Interaction Type is Harvest
  57.     local interactMode = GetInteractionType()
  58.     if interactMode  ~= INTERACTION_HARVEST then return end
  59.  
  60.     -- Check if we are still processing the last interaction update cycle
  61.     if interacting then return end
  62.     interacting = true
  63.  
  64.     -- Get some important information into variables for use later
  65.     local unitID = "player"
  66.     local zone = GetUnitZone(unitID)
  67.     local xPos,yPos,zPos = GetMapPlayerPosition(unitID)
  68.     local action, name, blocked, extra, context = GetGameCameraInteractableActionInfo()
  69.     local dateValue = GetDate()
  70.     local timeValue = GetTimeString()
  71.  
  72.     -- Just in case it thinks crafting is a harvestable object
  73.     if action == "Use" then
  74.         ChatMsg:AddMessage(string.format("Action: %s Name: %s Mode: %d Extra: %d",action,name,interactMode,extra))
  75.         return
  76.     end
  77.  
  78.     -- Does the node exist in the database ?
  79.     local nodeExists = SVDataExists(xPos,yPos,zone,name)
  80.     local NewOrOld = "New"
  81.     if nodeExists then NewOrOld = "Old" end
  82.  
  83.     -- Display information on the screen regardless if it is an old or new node
  84.     ChatMsg:AddMessage(string.format("[%s] %s: %s at ( x:%0.3f, y:%0.3f ) in %s",NewOrOld,action,name,xPos,yPos,zone))
  85.  
  86.     -- Only update the saved variable file if the node doesn't exist in there yet
  87.     if not nodeExists then
  88.         ChatMsg:AddMessage("Adding Harvest Node to Database")
  89.         SVData = SVData or {}
  90.         SVData["History"]                       = SVData["History"] or {}
  91.         SVData["History"]                       = SVData["History"] or {}
  92.         SVData["History"][zone]                 = SVData["History"][zone] or {}
  93.         SVData["History"][zone][name]           = SVData["History"][zone][name] or {}
  94.  
  95.         SVDataIndex = #SVData["History"][zone][name] + 1
  96.  
  97.         SVData["History"][zone][name][SVDataIndex]              = SVData["History"][zone][name][SVDataIndex] or {}
  98.         SVData["History"][zone][name][SVDataIndex]["Action"]    = action
  99.         SVData["History"][zone][name][SVDataIndex]["X"]         = xPos
  100.         SVData["History"][zone][name][SVDataIndex]["Y"]         = yPos
  101.         SVData["History"][zone][name][SVDataIndex]["Date"]      = dateValue
  102.         SVData["History"][zone][name][SVDataIndex]["Time"]      = timeValue
  103.     end
  104.  
  105.     ChatMsg:AddMessage("Traversing Harvest History")
  106.     for history,sv in pairs(SVData) do         
  107.         if history == "History" then
  108.             for zone, t1 in pairs(SVData[history]) do
  109.                 for item, t2 in pairs(SVData[history][zone]) do
  110.                     for index, t3 in pairs(SVData[history][zone][item]) do
  111.                         local data = SVData[history][zone][item][index]
  112.                         ChatMsg:AddMessage(string.format("%d: %s %s in %s at %0.3f,%0.3f",index,item,tostring(data["Action"]),zone,data["X"],data["Y"]))
  113.                     end
  114.                 end
  115.             end
  116.         end
  117.     end
  118.  
  119. end
  120.  
  121. -- Our Addon is loaded so we can start work
  122. local function AddOnLoaded(eventID,addon)
  123.     if addon ~= addonName then return end
  124.     EventMgr:UnregisterForEvent(addonName,eventID)
  125.     ChatMsg:AddMessage(string.format("%s %s Loaded",addonName,addonVersion))
  126.     InitSavedVariables()
  127.  
  128.         -- Have to have this here at this point to get the table traversing properly that session.  
  129.         -- If I remove this line the function error appears again and it won't traverse.
  130.     SVData["History"] = {}
  131. end
  132.  
  133. -- Track addons loading
  134. EventMgr:RegisterForEvent( addonName ,EVENT_ADD_ON_LOADED , AddOnLoaded )

Here is a screenshot of what is happening when I try and traverse through the table.

If I change the traversing to the following in the hopes of bypassing the other stuff I get the same problem:

Lua Code:
  1. for zone, t1 in pairs(SVData[history]) do
  2.                 for item, t2 in pairs(SVData[history][zone]) do
  3.                     for index, t3 in pairs(SVData[history][zone][item]) do
  4.                         local data = SVData[history][zone][item][index]
  5.                         ChatMsg:AddMessage(string.format("%d: %s %s in %s at %0.3f,%0.3f",index,item,tostring(data["Action"]),zone,data["X"],data["Y"]))
  6.                     end
  7.                 end
  8.             end

Again, only if the data exists when logging in.
Attached Thumbnails
Click image for larger version

Name:	Table Traversing Problem.jpg
Views:	585
Size:	270.9 KB
ID:	24  

Last edited by Xrystal : 03/02/14 at 04:51 PM.
  Reply With Quote