View Single Post
02/02/23, 08:33 PM   #7
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 247
Im close but getting errors i cant make sense of yet.

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")
        
	EVENT_MANAGER:UnregisterForEvent("RidinDirty", EVENT_ADD_ON_LOADED)
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)
and errors saving user. please ignore case I had to retyp from screenshot:
Code:
user:addons/ridindirty/ridindirty.lua:26: attempt to index a nil value
stack traceback:
user:addons/ridindirty/ridindirty.lua:26: in function 'RidinDirty.SaveMountOwner'
<locals> displaynametotaxiwith = "@XXXXXX" </locals>
:1: in function '(main chunk)'
<locals> keybind = "SAVE_MOUNT_OWNER" </locals>
  Reply With Quote