View Single Post
02/02/23, 08:43 PM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,028
You are not calling your Initialize function so there are no savedvars etc.
And you should not use the : notation if not needed (you'll learn that later on perhaps if needed). If your addon was created as a simple table like RidinDirty = {} you should define and call the functions with . notation!

So changed RidinDirty:Initialized to RidinDirty.Initialize and call it at event_add_on_loaded.

Lua Code:
  1. RidinDirty = {}
  2.  
  3. RidinDirty.svName = "RidinDirtyVars" --name of the SV table.
  4. --Dont forget to add the ##SavedVariables: MyAddonSavedVariables tag to your manifest txt file!
  5. --RidinDirty.savedVariables = {} --empty SV table of my addon
  6. function RidinDirty.Initialize()
  7.     RidinDirty.savedVariables = ZO_SavedVariables:NewAccountWide(RidinDirty.svName, RidinDirty.variableVersion, GetWorldName(), { lastMountOwner = nil }, nil, nil)
  8. end
  9.  
  10. local function OnAddOnLoaded(eventCode, addOnName)
  11.     if (addOnName ~= "RidinDirty") then return end
  12.  
  13.     EVENT_MANAGER:UnregisterForEvent("RidinDirty", EVENT_ADD_ON_LOADED)
  14.  
  15.     ZO_CreateStringId("SI_BINDING_NAME_MOUNT_OWNER", "Mount Owner")
  16.     ZO_CreateStringId("SI_BINDING_NAME_SAVE_MOUNT_OWNER", "Save Mount Owner")
  17.        
  18.     RidinDirty.Initialize()
  19. end
  20.  
  21. --Define the function to save the target displayname below the retilce to the SavedVariables
  22. function RidinDirty.SaveMountOwner()
  23.    local displayNameToTaxiWith = GetUnitDisplayName("reticleover")
  24.    if displayNameToTaxiWith == nil or displayNameToTaxiWith == "" then return end
  25.    
  26.    RidinDirty.savedVariables.lastMountOwner = displayNameToTaxiWith
  27. end
  28.  
  29. --Define the function to Mount with the last saved target
  30. function RidinDirty.MountWithSavedOwner()
  31.    local lastMountOwner = RidinDirty.savedVariables.lastMountOwner
  32.    if lastMountOwner  == nil or lastMountOwner  == "" then return end
  33.    
  34.    UseMountAsPassenger(lastMountOwner)
  35. end
  36.  
  37. EVENT_MANAGER:RegisterForEvent("RidinDirty", EVENT_ADD_ON_LOADED, OnAddOnLoaded)



btw the error message told you:
line 26 = RidinDirty.savedVariables.lastMountOwner = displayNameToTaxiWith
Error "attempt to index a nil value"
It tries to index a table (RidinDirty.savedVariables), which is nil (as your Initialize function was not called and thus the table was not created)
  Reply With Quote