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:
RidinDirty = {}
RidinDirty.svName = "RidinDirtyVars" --name of the SV table.
--Dont forget to add the ##SavedVariables: MyAddonSavedVariables tag to your manifest txt file!
--RidinDirty.savedVariables = {} --empty SV table of my addon
function RidinDirty.Initialize()
RidinDirty.savedVariables = ZO_SavedVariables:NewAccountWide(RidinDirty.svName, RidinDirty.variableVersion, GetWorldName(), { lastMountOwner = nil }, nil, nil)
end
local function OnAddOnLoaded(eventCode, addOnName)
if (addOnName ~= "RidinDirty") then return end
EVENT_MANAGER:UnregisterForEvent("RidinDirty", EVENT_ADD_ON_LOADED)
ZO_CreateStringId("SI_BINDING_NAME_MOUNT_OWNER", "Mount Owner")
ZO_CreateStringId("SI_BINDING_NAME_SAVE_MOUNT_OWNER", "Save Mount Owner")
RidinDirty.Initialize()
end
--Define the function to save the target displayname below the retilce to the SavedVariables
function RidinDirty.SaveMountOwner()
local displayNameToTaxiWith = GetUnitDisplayName("reticleover")
if displayNameToTaxiWith == nil or displayNameToTaxiWith == "" then return end
RidinDirty.savedVariables.lastMountOwner = displayNameToTaxiWith
end
--Define the function to Mount with the last saved target
function RidinDirty.MountWithSavedOwner()
local lastMountOwner = RidinDirty.savedVariables.lastMountOwner
if lastMountOwner == nil or lastMountOwner == "" then return end
UseMountAsPassenger(lastMountOwner)
end
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)