• 0

    posted a message on Subscribing To My Addon's Comments?
    Quote from Elkano
    Did you try here? http://www.curse.com/my-profile/activity (the envelopes in front)


    Ah, thanks, I will try that.

    Cheers!
    Posted in: General Chat
  • 0

    posted a message on Subscribing To My Addon's Comments?
    Nowhere else to post this as Site Issues & Suggestions is non existent.

    I have never received any emails for comments posted on my addons. I am subscribed in CurseForge: http://wow.curseforge.com/addons/dejamark/manage-subscriptions/ All selected, all email, all live, am I doing something wrong? I have checked that I have the correct email listed and have gone through my spam email. I also get monthly emails from Curse so i am curious what else to look for.

    Thanks for any assistance.

    Cheers!
    Posted in: General Chat
  • 0

    posted a message on In Game Cinemeatic Event API Call?
    I am looking for whatever event fires once in game cinematics are over and close.

    I have moved the micro menu buttons and when a movie plays it gets reset to default position.


    If I do this simple movement:

    	CharacterMicroButton:ClearAllPoints()
    	CharacterMicroButton:SetPoint("CENTER",UIParent,"CENTER",0,0)
    


    Everything works fine until an in game cinematic plays. It places it back into the default position.

    I have also tried triggering itself with events:

    local function eventHandler(self, event, ...)
    	for i = 1, 1 do
    		if CharacterMicroButton then
    	CharacterMicroButton:ClearAllPoints()
    	CharacterMicroButton:SetPoint("CENTER",UIParent,"CENTER",0,0)
    		end
    	end
    end
    
    CharacterMicroButton:SetScript("OnEvent",eventHandler)
    


    Triggering outside events also trying HookScript in case it is protected:

    	CharacterMicroButton:HookScript("OnEvent", function(self, event, arg1)
    		if event == "PLAYER_LOGIN" then
    			self:ClearAllPoints()
    			self:SetPoint("CENTER",UIParent,"CENTER",0,0)
    		end
    	end)


    All to no avail.

    Any ideas anyone ? :)

    Thanks for any help

    Cheers!

    To clarify I have tried the following which is both standard fare as well as what is registered in the default micro menu frames:
    "CINEMATIC_STOP"
    "PLAYER_LOGIN"
    "PLAYER_ENTERING_WORLD"
    "UPDATE_BINDINGS"
    "NEUTRAL_FACTION_SELECT_RESULT"
    "UNIT_PORTRAIT_UPDATE"
    "UPDATE_SHAPESHIFT_FORM"
    "UPDATE_SHAPESHIFT_FORMS"
    "UPDATE_STEALTH"
    "UPDATE_BONUS_ACTIONBAR"
    "PET_BATTLE_OVER"
    "PET_BATTLE_CLOSE"

    I also went through the entire Event catalog A - Z and looked for and tried anything that I thought may work either by direct reference or indirect means, short of an OnUpdate or Player Regen Enabled finagling.
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Quote from Phanx
    ...

    You shouldn't be responding to ADDON_LOADED in your module files, since you can't guarantee that the event handler in a given module file will run before the event handler in your core file, so your saved variables table might not have been initialized with default values yet when a module event handler runs. Use PLAYER_LOGIN instead in your modules.
    ...


    I thought I ran into this already, but even with the recent script above it appears that the dvstanceframe is created before the dvpetframe which is annoying since they are my frames. i ended up just anchoring the dvstanceframe to the MultiBarBottomRightButton1 and increasing its yOffset from 6 to 44 and it works fine.
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Are you suggesting I place my defaults into the core file and then use a local?

    local point = private.db.petSetPoints
    self:SetPoint(point.point, point.relativeTo, point.relativePoint, point.xOffset,point.yOffset)

    Also, how would I nest? Is this correct?

    I changed to petSetPoints to be more descriptive with so many variables, although I am not quite certain of its practicality because of the SetPoint() function.

    [code]local _, private = ... private.defaults.petSetPoints = { point = "BOTTOMLEFT", relativeTo = "MultiBarBottomRightButton1", relativePoint = "TOPLEFT", xOffset = 0, yOffset = 6, } private.defaults.stanceSetPoints = { point = "BOTTOMLEFT", relativeTo = "MultiBarBottomRightButton1", relativePoint = "TOPLEFT", xOffset = 0, yOffset = 44, } private.defaults.rightsidebarsSetPoints = { point = "BOTTOMRIGHT", relativeTo = "Minimap", relativePoint = "BOTTOMLEFT", xOffset = 0, yOffset = 0, } private.defaults.micromenuSetPoints = { point = "BOTTOMRIGHT", relativeTo = "Minimap", relativePoint = "TOPRIGHT", xOffset = 0, yOffset = 0, } private.defaults.bagsSetPoints = { point = "BOTTOMRIGHT", relativeTo = "dvrsbframe", relativePoint = "BOTTOMLEFT", xOffset = 0, yOffset = 0, }[/code]

    Then I am setting and saving like this but I question if I am calling the table values correctly and saving to them correctly. Since I have several variables i cant set them all to "point" outside so I call them within their respective function. Outside of nesting both functions inside another frame is there a way to set and call "local point = private.db.petSetPoints" once within the module's file?: EDIT...change the variable name from point to whatever...I am getting tired, lol.

    [code]-- DVPetFrame local dvpetframe = CreateFrame("Frame", "DejaViewPetFrame", UIParent) -- you can't place the frame yet since your saved settings haven't loaded yet dvpetframe:RegisterEvent("PLAYER_LOGIN") dvpetframe:SetFrameStrata("HIGH") dvpetframe:SetClampedToScreen(true) dvpetframe:SetMovable(true) dvpetframe:EnableMouse(true) dvpetframe:RegisterForDrag("LeftButton") dvpetframe:SetWidth(318) dvpetframe:SetHeight(38) dvpetframe:Show() dvpetframe:SetScript("OnEvent", function(self, event, arg1) if event == "PLAYER_LOGIN" then [COLOR="DarkOrchid"] local point = private.db.petSetPoints[/COLOR] self:ClearAllPoints() self:SetPoint( point.point, point.relativeTo, point.relativePoint, point.xOffset, point.yOffset) self:UnregisterEvent("PLAYER_LOGIN") end end) dvpetframe:SetScript("OnDragStart", dvpetframe.StartMoving) dvpetframe:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() self:SetUserPlaced(false) point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint(1) if ( relativeTo ) then relativeTo = relativeTo:GetName(); else relativeTo = self:GetParent():GetName(); end -- These are debugging messages for the frame points -- Un-comment them to help debug -- DEFAULT_CHAT_FRAME:AddMessage(point) -- DEFAULT_CHAT_FRAME:AddMessage(relativeTo) -- DEFAULT_CHAT_FRAME:AddMessage(relativePoint) -- DEFAULT_CHAT_FRAME:AddMessage(xOfs) -- DEFAULT_CHAT_FRAME:AddMessage(yOfs) [CODE] local point = private.db.petSetPoints[/code]
    point.point = point
    point.relativeTo = relativeTo
    point.relativePoint = relativePoint
    point.xOffset = xOfs
    point.yOffset = yOfs
    end)[/CODE]
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Ok, so this is our table that is empty until the database is initialized:

    DejaView.lua core file

    --SavedVariables Setup
    local DejaView, private = ...
    
    private.defaults = {
        -- If you have any general settings for you addon,
        -- list them here, or just leave the table empty.
    }
    


    Then we initialize it. it looks in the saved variables to see if there is anything and if there is not it proceeds to copy the defaults into the empty table above, and or copy the saved variables into the table above, filling up the table with the appropriate data to be used by the addon:

    DejaView.lua core file continued...

    local loader = CreateFrame("Frame")
    	loader:RegisterEvent("ADDON_LOADED")
    	loader:SetScript("OnEvent", function(self, addon)
    		if addon ~= DejaView then 
    			local function initDB(db, defaults)
    				if type(db) ~= "table" then db = {} end
    				if type(defaults) ~= "table" then return db end
    				for k, v in pairs(defaults) do
    					if type(v) == "table" then
    						db[k] = initDB(db[k], v)
    					elseif type(v) ~= type(db[k]) then
    						db[k] = v
    					end
    				end
    			return db
    			end
    
    		DejaViewDBPC = initDB(DejaViewDBPC, private.defaults)
    [COLOR="DarkOrchid"]		private.db = DejaViewDBPC -- add this[/COLOR]
    		self:UnregisterEvent("ADDON_LOADED")
    		-- Don't place any frames here
    		end
    	end)


    Before the above happens with ADDON_LOADED, all of the files are read and the module's local defaults which are located in a different file within the addon for that module, DejaBars.lua, are available to be copied if there are no saved variables and the following code is either used to copy the defaults from or ignored because there are saved variables. Either way we are done with the following chunk as it has served its purpose:

    DejaBars.lua module file
    local _, private = ...
    private.defaults.mainbars = {
        -- settings for this file's stuff
    	petPoints = {
    		point = "BOTTOMLEFT", 
    		relativeTo = "MultiBarBottomRightButton1", 
    		relativePoint = "TOPLEFT", 
    		xOffset = 20, 
    		yOffset = 6,
    	}
    }



    So now the table is filled with the appropriate data so we should get the data from this table and not the defaults that I was doing previously with self.db. Instead I use the table reference private.db which is created upon initialization with the association of private.db = DejaViewDBPC and we then use the following to set the frames and save variables that change :

    DejaBars.lua module file continued...
    dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			self:ClearAllPoints()		
    			self:SetPoint(
    			[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.point, 
    			[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.relativeTo, 
    			[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.relativePoint, 
    			[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.xOffset, 
    			[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.yOffset)
    			self:UnregisterEvent("ADDON_LOADED")
    		end
    	end)
    	
    	dvpetframe:SetScript("OnDragStart", dvpetframe.StartMoving) 
    	
    	dvpetframe:SetScript("OnDragStop", function(self) 
    		self:StopMovingOrSizing() 
    		self:SetUserPlaced(false) 
    		
    		point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint(1)
    			if ( relativeTo ) then
    				relativeTo = relativeTo:GetName();
    			else
    				relativeTo = self:GetParent():GetName();
    			end
    
    	        -- These are debugging messages for the frame points
                    -- Un-comment them to help debug
    		-- DEFAULT_CHAT_FRAME:AddMessage(point)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativeTo)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativePoint)
    		-- DEFAULT_CHAT_FRAME:AddMessage(xOfs)
    		-- DEFAULT_CHAT_FRAME:AddMessage(yOfs)
    		
    		[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.point = point
    		[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.relativeTo = relativeTo
    		[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.relativePoint = relativePoint
    		[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.xOffset = xOfs
    		[COLOR="DarkOrchid"]private.db.[/COLOR]mainbars.petPoints.yOffset = yOfs		
    	end)


    So before with the self.db implementation I was using, the files were read before the ADDON_LOADED which triggers the database initialization. So my use of self.db as I did before was using the defaults directly, changing them in memory by setting new variables when the OnDragStop function fires and then saving on reload or logout with a reverse association to local DejaView, private = ... via the association local _, private = ... ?

    Or is SavedVariablesPerCharacter an API function that saves it somehow? how was it saving? Some weird loop?

    So now with the private.db = DejaViewDBPC implementation it reads all the files, ADDON_LOADED fires, the database is initialized and the addon can use the appropriate data for frame placement as it is derived from the real table and changes are saved to the real table to be saved to the saved variables file all directly on reload or logout.

    This also has the real table and defaults only referenced one time each instance instead of both at the same time but separately with weird default changes or reverse associations to the defaults and or table in memory? Was this causing a loop?

    Is this correct? It still works however, I would really like to understand it for when things get more complicated, plus it is pretty damned cool.

    Thanks :)
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Thanks again Phanx.

    To followup as my, hopefully, final implementation I am using the following:

    Core File Dejaview.lua
    --SavedVariables Setup
    local DejaView, private = ...
    
    private.defaults = {
        -- If you have any general settings for you addon,
        -- list them here, or just leave the table empty.
    }
    
    local loader = CreateFrame("Frame")
    	loader:RegisterEvent("ADDON_LOADED")
    	loader:SetScript("OnEvent", function(self, addon)
    		if addon ~= DejaView then 
    			local function initDB(db, defaults)
    				if type(db) ~= "table" then db = {} end
    				if type(defaults) ~= "table" then return db end
    				for k, v in pairs(defaults) do
    					if type(v) == "table" then
    						db[k] = initDB(db[k], v)
    					elseif type(v) ~= type(db[k]) then
    						db[k] = v
    					end
    				end
    			return db
    			end
    
    		DejaViewDBPC = initDB(DejaViewDBPC, private.defaults)
    		self:UnregisterEvent("ADDON_LOADED")
    		-- Don't place any frames here
    		end
    	end)


    Individual default settings for each modular file, This example is DejaBars.lua

    local _, private = ...
    private.defaults.mainbars = {
        -- settings for this file's stuff
    	petPoints = {
    		point = "BOTTOMLEFT", 
    		relativeTo = "MultiBarBottomRightButton1", 
    		relativePoint = "TOPLEFT", 
    		xOffset = 20, 
    		yOffset = 6,
    	}
    }


    Then for each frame I have default settings for I place it like this:

    	dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			self.db = DejaViewDBPC
    			self:ClearAllPoints()		
    			self:SetPoint(
    			self.db.mainbars.petPoints.point, 
    			self.db.mainbars.petPoints.relativeTo, 
    			self.db.mainbars.petPoints.relativePoint, 
    			self.db.mainbars.petPoints.xOffset, 
    			self.db.mainbars.petPoints.yOffset)
    			self:UnregisterEvent("ADDON_LOADED")
    		end
    	end)
    


    Then for saving new positions on drag I use this for the same frame above:

    	dvpetframe:SetScript("OnDragStart", dvpetframe.StartMoving) 
    	
    	dvpetframe:SetScript("OnDragStop", function(self) 
    		self:StopMovingOrSizing() 
    		self:SetUserPlaced(false) 
    		
    		point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint(1)
    			if ( relativeTo ) then
    				relativeTo = relativeTo:GetName();
    			else
    				relativeTo = self:GetParent():GetName();
    			end
    	
    		-- DEFAULT_CHAT_FRAME:AddMessage(point)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativeTo)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativePoint)
    		-- DEFAULT_CHAT_FRAME:AddMessage(xOfs)
    		-- DEFAULT_CHAT_FRAME:AddMessage(yOfs)
    		
    		self.db.mainbars.petPoints.point = point
    		self.db.mainbars.petPoints.relativeTo = relativeTo
    		self.db.mainbars.petPoints.relativePoint = relativePoint
    		self.db.mainbars.petPoints.xOffset = xOfs
    		self.db.mainbars.petPoints.yOffset = yOfs		
    	end)


    The only problem I had was wrapping my head around my saved variables file containing my local defaults,

    private.defaults.mainbars.petPoints.point

    But it doesn't write because it is not accessing my saved variable table DejaViewDBPC. I had to reference DejaViewDBPC which contains my locals mainbars.petPoints.point

    So referring back to the protocol I used self.db to reference DejaViewDBPC and then my local defaults

    self.db.mainbars.petPoints.point

    And when using the OnDragStop script above it is able to then write the new locations to

    mainbars.petPoints

    For clarification, here is what my DejaView.lua saved variable file looks like after moving the frame above:

    DejaViewDBPC = {
    	["mainbars"] = {
    		["petPoints"] = {
    			["relativeTo"] = "UIParent",
    			["point"] = "RIGHT",
    			["relativePoint"] = "RIGHT",
    			["xOffset"] = -274.154327392578,
    			["yOffset"] = 228.145401000977,
    		},
    	},
    }


    Am I missing anything for the above? It is working as I wish and I think I am finished but I would like to make sure I am not doing anything weird or that could be done more easily, clearly or remove things that may not need to be done at all.

    Thank you again.

    Cheers!
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Ok so the frame was moving around after a reload/logout, I think because the parent and/or relative frame is changed on StopMovingOrSizing().

    So I changed it to this, seems to be working well.
    -- DVPetFrame
    local DEFAULT_SETTINGS = {
    	petPoints = {
    		petpoint = "BOTTOMLEFT", 
    		petrelativeTo = "MultiBarBottomRightButton1", 
    		petrelativePoint = "TOPLEFT", 
    		petxOffset = 0, 
    		petyOffset = 6,
    	}
    
    }
    
    local dvpetframe = CreateFrame("Frame", "DejaViewPetFrame", UIParent)
    	-- you can't place the frame yet since your saved settings haven't loaded yet
    	dvpetframe:RegisterEvent("ADDON_LOADED")
    	dvpetframe:SetFrameStrata("HIGH")
    	dvpetframe:SetClampedToScreen(true)
    	dvpetframe:SetMovable(true)
    	dvpetframe:EnableMouse(true)
    	dvpetframe:RegisterForDrag("LeftButton")
    	dvpetframe:SetWidth(318)
    	dvpetframe:SetHeight(38)
    	dvpetframe:Show()
    
    	dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			-- Initialize the database
    			local function initDB(db, defaults)
    				if type(db) ~= "table" then db = {} end
    				if type(defaults) ~= "table" then return db end
    				for k, v in pairs(defaults) do
    					if type(v) == "table" then
    						db[k] = initDB(db[k], v)
    					elseif type(v) ~= type(db[k]) then
    						db[k] = v
    					end
    				end
    				return db
    			end
    
    			DejaViewDBPC = initDB(DejaViewDBPC, DEFAULT_SETTINGS)
    			self.db = DejaViewDBPC 
    			-- "self.db" is the conventional name to use here; while it makes no real difference,
    			-- it will make it easier to compare your code to documentation and other addons.
    			self:UnregisterEvent("ADDON_LOADED")
    			-- NOW you can place the frame:
    			self:ClearAllPoints()		
    			self:SetPoint(self.db.petPoints.petpoint, self.db.petPoints.petrelativeTo, self.db.petPoints.petrelativePoint, self.db.petPoints.petxOffset, self.db.petPoints.petyOffset)
    		end
    	end)
    
    	dvpetframe:SetScript("OnDragStart", dvpetframe.StartMoving) 
    	
    	dvpetframe:SetScript("OnDragStop", function(self) 
    		self:StopMovingOrSizing() 
    		self:SetUserPlaced(false) 
    		
    		point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint(1)
    			if ( relativeTo ) then
    				relativeTo = relativeTo:GetName();
    			else
    				relativeTo = self:GetParent():GetName();
    			end
    	
    		-- DEFAULT_CHAT_FRAME:AddMessage(point)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativeTo)
    		-- DEFAULT_CHAT_FRAME:AddMessage(relativePoint)
    		-- DEFAULT_CHAT_FRAME:AddMessage(xOfs)
    		-- DEFAULT_CHAT_FRAME:AddMessage(yOfs)
    		
    		self.db.petPoints.petpoint = point
    		self.db.petPoints.petrelativeTo = relativeTo
    		self.db.petPoints.petrelativePoint = relativePoint
    		self.db.petPoints.petxOffset = xOfs
    		self.db.petPoints.petyOffset = yOfs		
    	end)


    So now how do I, or am I able to initialize the database once globally and then call the variables of DejaViewDBPC?

    I have ten frames, does reinitializing 10 times each time each frame is loaded effect efficiency or anything else?

    I was thinking I could nest them in an initialization frame I could create but I am still using several .lua files to try to maintain modularity so that would still incur 4 or 5 initializations.

    Is it best to just have one big .lua file and nest it all within an initialization frame top to bottom?

    Here is what I was thinking, but I'd rather stay modular.

    local DEFAULT_SETTINGS = {
    	petPoints = {
    		petpoint = "BOTTOMLEFT", 
    		petrelativeTo = "MultiBarBottomRightButton1", 
    		petrelativePoint = "TOPLEFT", 
    		petxOffset = 0, 
    		petyOffset = 6,
    	}
    	otherPoints = {
    		otherpoint = "BOTTOMLEFT", 
    		otherrelativeTo = "MultiBarBottomRightButton1", 
    		otherrelativePoint = "TOPLEFT", 
    		otherxOffset = 0, 
    		otheryOffset = 6,
    	}
    }
    
    [B][COLOR="darkorchid"]-- New initialization frame[/COLOR][/B]
    local dvInitFrame = CreateFrame("Frame", "DejaViewPetFrame", UIParent)
    	dvInitFrame:RegisterEvent("ADDON_LOADED")
    	dvInitFrame:SetFrameStrata("HIGH")
    	dvInitFrame:SetClampedToScreen(true)
    	dvInitFrame:SetMovable(true)
    	dvInitFrame:EnableMouse(true)
    	dvInitFrame:RegisterForDrag("LeftButton")
    	dvInitFrame:SetWidth(318)
    	dvInitFrame:SetHeight(38)
    	dvInitFrame:Show()
    
    	dvInitFrame:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			local function initDB(db, defaults)
    				if type(db) ~= "table" then db = {} end
    				if type(defaults) ~= "table" then return db end
    				for k, v in pairs(defaults) do
    					if type(v) == "table" then
    						db[k] = initDB(db[k], v)
    					elseif type(v) ~= type(db[k]) then
    						db[k] = v
    					end
    				end
    				return db
    			end
    
    			DejaViewDBPC = initDB(DejaViewDBPC, DEFAULT_SETTINGS)
    			self.db = DejaViewDBPC 
    			self:UnregisterEvent("ADDON_LOADED")
    			[B][COLOR="darkorchid"]-- Don't place any frames here[/COLOR][/B]
    		end
    
    [B][COLOR="darkorchid"]-- DVPetFrame[/COLOR][/B]
    local dvpetframe = CreateFrame("Frame", "DejaViewPetFrame", UIParent)
    
    	dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    	if event == "ADDON_LOADED" and arg1 == "DejaView" then
    		self.db = DejaViewDBPC 
    		self:UnregisterEvent("ADDON_LOADED")
    		[B][COLOR="darkorchid"]-- Place frames here instead[/COLOR][/B]
    		self:ClearAllPoints()		
    		self:SetPoint(self.db.petPoints.petpoint, self.db.petPoints.petrelativeTo, self.db.petPoints.petrelativePoint, self.db.petPoints.petxOffset, self.db.petPoints.petyOffset)
    	end
    	
    	dvpetframe:RegisterEvent("ADDON_LOADED")
    	dvpetframe:SetFrameStrata("HIGH")
    	dvpetframe:SetClampedToScreen(true)
    	dvpetframe:SetMovable(true)
    	dvpetframe:EnableMouse(true)
    	dvpetframe:RegisterForDrag("LeftButton")
    	dvpetframe:SetWidth(318)
    	dvpetframe:SetHeight(38)
    	dvpetframe:Show()
    	
    	dvpetframe:SetScript("OnDragStart", dvpetframe.StartMoving) 
    	
    	dvpetframe:SetScript("OnDragStop", function(self) 
    		self:StopMovingOrSizing() 
    		self:SetUserPlaced(false) 
    		
    		point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint(1)
    			if ( relativeTo ) then
    				relativeTo = relativeTo:GetName();
    			else
    				relativeTo = self:GetParent():GetName();
    			end
    
    		self.db.petPoints.petpoint = point
    		self.db.petPoints.petrelativeTo = relativeTo
    		self.db.petPoints.petrelativePoint = relativePoint
    		self.db.petPoints.petxOffset = xOfs
    		self.db.petPoints.petyOffset = yOfs		
    	end)
    
    [B][COLOR="darkorchid"]-- OtherFrames[/COLOR][/B]		
    local otherframe = CreateFrame("Frame", "OtherFrame", UIParent)
    	...
    	...
    	...
    	
    end) [B][COLOR="darkorchid"]-- End initialization frame[/COLOR][/B]
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Thank you everyone ;)

    Since I will be implementing this for practically every frame I made it will be a good time to review my variable names and make them more descriptive, thanks for the insight Phanx, it will save me a lot of time both reading my code later and/or having to review it separately at a later date.

    Any improvements or advice about what I have ended up with?

    -- DVPetFrame
    local DEFAULT_SETTINGS = {
    	petOffsetX = 0,
    	petOffsetY = 6,
    }
    
    local dvpetframe = CreateFrame("Frame", "DejaViewPetFrame", UIParent)
    	-- you can't place the frame yet since your saved settings haven't loaded yet
    	dvpetframe:RegisterEvent("ADDON_LOADED")
    	dvpetframe:SetFrameStrata("HIGH")
    	dvpetframe:SetClampedToScreen(true)
    	dvpetframe:SetMovable(true)
    	dvpetframe:EnableMouse(true)
    	dvpetframe:RegisterForDrag("RightButton")
    	dvpetframe:SetWidth(318)
    	dvpetframe:SetHeight(38)
    	dvpetframe:Show()
    
    	dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			-- Initialize the database
    			local function initDB(db, defaults)
    				if type(db) ~= "table" then db = {} end
    				if type(defaults) ~= "table" then return db end
    				for k, v in pairs(defaults) do
    					if type(v) == "table" then
    						db[k] = initDB(db[k], v)
    					elseif type(v) ~= type(db[k]) then
    						db[k] = v
    					end
    				end
    				return db
    			end
    
    			DejaViewDBPC = initDB(DejaViewDBPC, DEFAULT_SETTINGS)
    			self.db = DejaViewDBPC 
    			-- "self.db" is the conventional name to use here; while it makes no real difference,
    			-- it will make it easier to compare your code to documentation and other addons.
    			self:UnregisterEvent("ADDON_LOADED")
    			-- NOW you can place the frame:
    			self:SetPoint("BOTTOMLEFT", MultiBarBottomRightButton1, "TOPLEFT", self.db.petOffsetX, self.db.petOffsetY)
    		end
    	end)
    
    	dvpetframe:SetScript("OnDragStart", function(self) 
    		if IsAltKeyDown() then 	
    			dvpetframe:StartMoving() 
    		end 
    	end)
    	dvpetframe:SetScript("OnDragStop", function(self) 
    		dvpetframe:StopMovingOrSizing() 
    		dvpetframe:SetUserPlaced(false) 
    		-- SetUserPlaced(false) prevents saving frame position
    		-- to layout-local.txt and overriding the savedvariables.
    		self.db.petOffsetX = dvpetframe:GetLeft()
    		-- Get xoff OnDragStop. It is saved with reloadui or logout.
    		self.db.petOffsetY = dvpetframe:GetTop()
    		-- Get xoff OnDragStop. It is saved with reloadui or logout.
    	end)
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Quote from Phanx
    Your code will not work because:

    1. No variable named "settings" has been defined yet when this code runs.


    Yea I know, I tried settings() thinking maybe the ACEDB does something. And I tried removing settings but then couldn't figure out how to initialize it and just went back to your method, but the ACE stuff is interesting.

    Quote from Phanx
    2. Since your database has not yet been initialized, your saved variables are not yet available here.


    Same as above, mostly I am ignorant of what ACE actually does. I started to read the documentation and tried their examples and will delve into that further when ig et a chance.

    Quote from Phanx
    There, you are creating a global variable named "settings". This is bad because (a) globals are slow, and (b) a name like "settings" is very likely to conflict with other addons or even the default UI if they also leak a global with the same name.


    I was thinking that maybe the "local settings" would speed it up etc,but couldnt figure out how to initialize it or set it to anything.Also, this is example code that Adirelle gave me with his ACE recommendation above so I was just keeping the generic format for testing purposes.

    Quote from Phanx
    (On a side note, you should use table key names that actually make sense. It looks like "dvpet" is storing x,y offsets for the position of the pet frame, so a descriptive name like "petOffset" would improve the ease of reading and maintaining your code. Though personally I'd just use two keys like "petOffsetX" and "petOffsetY" instead of wasting memory on a sub-table.)


    I am bad about doing this and tend to start out with something like dvpetframeoffsetcoordx and dvpetframeoffsetcoordy and think, wow that is too descriptive, and then overcompensate, lol.

    Quote from Phanx
    I think you mean something more like this:

    Thank you so much Phanx for all of your help and patience, as always :) I can't wait to wake up tomorrow and work on this.

    Cheers!
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    -- Then use settings, e.g.:
    local dvb = settings.char.dvb

    -- Or set them:
    settings.char.dvb = {6, 7}


    Do I have to set local and global?

    Also I am trying to have these either across .lua files or individually declared for each file's variables.

    IE will this work or will it set up redundant tables or cause other issues like loops or weird stuff?:

    -- DVPetFrame
    local DEFAULT_SETTINGS = {
        char = {
    	dvpet = {0, 6},
        }
    }
    
    -- DVPetFrame
    local dvpet = settings.char.dvpet
    settings.char.dvb = {6, 7}
    local dvpetframe=CreateFrame("Frame", "dvpetframe", UIParent)
    	dvpetframe:SetPoint("BOTTOMLEFT", MultiBarBottomRightButton1, "TOPLEFT", dvpet)
    	
    	dvpetframe:RegisterEvent("ADDON_LOADED")
    	dvpetframe:SetScript("OnEvent", function(self, event, arg1)
    		if event == "ADDON_LOADED" and arg1 == "DejaView" then
    			-- Initialize the database
    			settings = LibStub('AceDB-3.0'):New("DejaViewDB", DEFAULT_SETTINGS)
    			self:UnregisterEvent("ADDON_LOADED")
    		end
    	end)


    At the moment I just want to save across sessions, but I intend to implement the ability to enable and disable each module, DejaMinimap, DejaChat, etc, individually and as mentioned implement a slider for each frame's scale, so I will need to delve into this and Ace3DB looks like a great solution for future-proofing, so to speak. However I am still a novice script writer and globals have confused me thus far.

    I read an explanation to declare a global and then set a local equal to the global so that you are not messing with the global environment, only getting info from it. So, is this the case and are globals a no no for use across .lua files or addons altogether?

    Thank you for your help and patience :)

    Cheers!
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    I get this error:

    line 63:

    local dvpet = settings.char.dvpet



    Message: Interface\AddOns\DejaView\DejaBars.lua:63: attempt to index global 'settings' (a nil value)
    Time: 10/31/14 10:48:44
    Count: 1
    Stack: Interface\AddOns\DejaView\DejaBars.lua:63: in main chunk
    
    Locals: mbars = mbars {
     0 = <userdata>
    }
    (*temporary) = nil
    (*temporary) = mbars {
     0 = <userdata>
    }
    (*temporary) = 476
    (*temporary) = 36
    (*temporary) = <userdata>
    (*temporary) = <userdata>
    (*temporary) = 0
    (*temporary) = <userdata>
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = "attempt to index global 'settings' (a nil value)"
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Thanks Adirelle I will give it a shot :)
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Quote from Dejoblue
    ... I have manually edited the saved variable file and changed the values and it resets to these defaults when I log in.
    ...


    I figured out I cant edit the file because it saves what is in memory...duh. But that is as far as I have gotten, more research in store, heh :)
    Posted in: Need Help?
  • 0

    posted a message on Global & SavedVariables Help
    Here is a jsfiddle. It shows where I have come to. Feel free to edit it with solutions and comment to explain, don't forget to hit update :).

    Thanks again.

    http://jsfiddle.net/dejoblue/8yrfxg50/
    Posted in: Need Help?
  • To post a comment, please or register a new account.